Posts: 10
Joined: Sun Apr 06, 2014 2:04 pm

Shell script project

Sun Apr 06, 2014 2:14 pm

i need to write a shell script that first comes up with a menu giving 4 options. Firstly ' 1) display a list of current users' ; ' 2) display a list of all files including hidden files in the home directory(i believe using the ls -a command)' ; 3) output a calender for the current month( i believe using the 'cal' command)' ; 4) and finally to be able to quit the script. The user can choose these options from a menu. I have be trialing many techniques, but with no luck! If anyone can help it would be much appreciated! :D

User avatar
Posts: 285
Joined: Fri Oct 28, 2011 7:41 am
Contact: Website Twitter

Re: Shell script project

Sun Apr 06, 2014 2:20 pm

Besides learning some simple bash script programming, I believe the tool 'dialog' will be appropriate here.

I don't know for certain, but I believe raspi-config uses it. Or at least, using dialog will produce menus that achieve a similar look and feel.

There's some docs here.

Hope this helps!

User avatar
Posts: 17454
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Shell script project

Sun Apr 06, 2014 3:26 pm

Actually raspi-config uses "whiptail" which can produce some pretty menus and return the results to scripts. It's a replacement for "dialog".

However you can easily do simple menus in Bash (or other shells) as I have been doing for many years. Something like: clear screen using the "clear" command, then echo a load of options and "read response" then check that $response is valid. Stick the whole thing in a "while" loop and Robert's your father's brother ;)

(psuedo code - not real bash)

Code: Select all

while [ "$valid" = "n" ]
    display menu items
    read response
    check response for valid values
    if response is valid, set valid="y"

Posts: 10
Joined: Sun Apr 06, 2014 2:04 pm

Re: Shell script project

Tue Apr 08, 2014 7:45 pm

Thanks very much, will look into it! :D

Return to “Advanced users”