Creating Command Line Menus with Shell Scripts

preview_player
Показать описание
For some users they will not know how to navigate the Linux CLI and perhaps it is best to provide them with a menu upon login. If we write this menu with a shell script then we can run it from their .bashrc login script using exec [scriptname] to ensure that leaving the script also logs them out. We can use a while loop to ensure the menu is shown after each selection and a case statement to read the users's selection. To ensure users cannot cntrl+c out of the meny we trap the signal so that it is ignored byt he script.
Рекомендации по теме
Комментарии
Автор

Nice, thanks!  Been looking for something like this for a long time.  Not being proficient in bash scripting, I appreciate the head-start.  One suggestion if your menu is going to use 1 character input (number or letter), perhaps change the "read answer" command to: read -n1 -p "Your Choice:" answer    (no [Return] required)

byteman
Автор

Still useful in 2021. Used this to build out a menu to give controlled and simplified access to a new appliance of ours. Thanks!

jonchellis
Автор

This is great thank you for all that you teach up with Linux. I am still learning and it never ends.

earnestredwood
Автор

At 6:10 or so, 4, 18> is a simpler, more direct way to indent code. It seems like overkill to use a regex and s/// to indent contiguous lines of code, so a pattern match and replace just isn't needed. 

Also, I think if you want a couple lines between the choices and the prompt, a couple of echo statements all by themselves is more straightforward than the echo -e "\n", e.g.:

echo
echo

I would also use read statements in place of the two prompts using the echo -n (text) because I think it is more readable and easy to understand expressed as:

read -p "Enter your selection " answer
...
read -p "Enter return to continue" input

meiowalot
Автор

If I want the users to enter both Uppercase and Lowercase alphabet for the menu selection, what should I put before the ) to instead? Thx.

jentr
Автор

This Bob here, he's been sharing his password with me, lol

DDBAA
Автор

Excellent guide! That was soo helpful like so many of your videos. Great job!

derSchmidi
Автор

I really fond of the vi substitution vi tricks that you perform, can you make a video that explain the trick? It's will be helpfull for anyone when they work on shell programming environment.

vincentpham
Автор

This is absolutly fantastic. Thank you so much for doing it :)

thDoctorLove
Автор

Thank you very much! Follow your video I build a little script to use a list of online FM stations using mplayer for it. I just add a line with a timer sleep on the script. Nice!

mxa
Автор

Nice! The "Enter return to continue" works great for commands like "who" that need to print to the screen, but my menu also launches graphical apps like firefox, audacious, etc, and it sucks to have to hit return after closing them in order to continue. How can I structure my script so that I see the output for commands like who and cal, but does NOT call for entering return when launching gui apps? Thanks

plasticinthetree
Автор

It really should have a default condition in the event the user enters something other than the three things the menu has handlers for.

adriansrealm
Автор

Whoah, sound is hurting.... Otherwise great one, thanks! I wasted a lot of time searching this topic

karakurt
Автор

Can the commands that you put in the menu only be commands that the particular user would usually have permission to carry out.?
Or could I, for instance set a menu option that only myself as root would usually be able carry out.

Trevs-Shed
Автор

love you brother >> you solve my big problem love you again

DBINB-swow
Автор

Love the videos, but can you do some volume leveling going forward? It's always brutal during the intro then quieter during the content portion of the video.

AwesomeBob
Автор

dose the trap and control c work on osx Mac?

jmac
Автор

Would there be any point, pointing out your mistakes in a video, as you are not really going to hear us LOL. PS what editor are you using. I tried this in nano, but some things don't work

Asimov
Автор

Please don’t use white it hurts my eyes 👀

sciencelover
visit shbcf.ru