Linux 93 (Case Statement Scripts)

Опубликовано: 02 Июнь 2026
на канале: LinXL Lab
89
4

Case Statement Scripts

Hello, friends. Welcome to my channel, beginner's Linux guide. Today, I'm going to tell you about the case scripts, how it is done. Let's see. First, whoamI, hostname, pwd. Now, I'm going to give you the case statement scripts. Let's take an example like if option A is selected, equals do this. If option B is selected, do this. And option C is selected, do this. Let's see in the practical. First, ls-ltr. These are the files we have. Let's create another file called vi-case1. Hit Enter. Now, to save our time, I have copied one script. Just I'm going to paste it. This is the script. First, it will give blank line echo, and then it will say, please choose one of the options below, such as, again, one blank and options are A, show the date and time, list file date, B, C, list user logged in, and D is display the current path. Then again, one blank line, and then read the choice. It will read the choices, and for that, it will case the choice. The dollar from choice means it will select my choice. The choices are, one is A, which is option A is date.

These are the all comments in Linux, we know that already. Now here we are running this as a script, as a choice, and as a case script. Second is ls, third is who, and fourth is pwd. And if any invalid choice has been given by you, then it will say echo invalid choice and by. And this is the end statement, esac. Let's save it. And again, ls -ltr. While it's there, give the permission. It is not yet script, need to give the permission. Chmod_case_1. Hit Enter. See, now it is there. Now run the script. Case_1. See, it is giving the choices like A show that. Let's say A. Hit Enter. It has given you. Again, you run the script. Now, this time, we'll give you C. Let's see. This is the logged in currently. Now, again, run the script. This time, we'll give the choice B. It will give you the details of it. Again, last one That time we'll see, say D, the choice. This is my home data. It is going to show you because I have given a PDF video over there. I just created the file. Let's see inside of the file.

Let's say I'm going to give a wrong choice now. In case, again, I'm running, I'm giving G, which is not there in my list. It will show you invert choice and buy because I have written like here, echo invert choice and buy. That's all folks for today. If you like my video, please do subscribe to my channel. It, share it, comment it, and don't forget to press the bell button so that whenever I post a new video over here, it gets on the description of it immediately. Thank you so much for being with me till the end of the video. Thank you so much for your love and support. We'll with you soon with another video with another topic. Thank you so much.

#technology #linux #unixcommands #freebsd #foss#viral