Matt
Matt

Reputation: 13

Basic menu BASH script in Lubuntu

I am creating a basic menu driven BASH script with 6 options, I was wondering if someone can give me a basic template of the script? #!/bin/bash Option 1) Option 2) Option 3) Option 4) Option 5) Option 6) Exit

Upvotes: 1

Views: 360

Answers (1)

sonologico
sonologico

Reputation: 764

Try the select statement. Example and template:

#!/bin/bash

select choice in opt1 opt2 opt3 opt4 opt5 exit
do
        case $choice in 
        opt1)   
                sl;
                fortune|cowsay -d;
                break;;
        opt2)   
                cd desktop/;
                mkdir textfiles;
                cd textfiles;
                touch 1.txt 2.txt 3.txt;
                cd ..;
                tar-cvf textfiles.tar textfiles/;
                break;;
        opt3)   
                echo 'You chose opt3';;
        opt4)   
                echo 'You chose opt4';;
        opt5)   
                echo 'You chose opt5';;
        exit)
                break;;
        *)
                echo 'Invalid option';;
        esac
done

I have inserted opt1 and opt2 as examples. Remember to use break;; if you want to exit the menu loop and choose better names than optN for the options.

Edit: I just copied opt1 and opt2 from your question. I haven't looked into them. If you need help with them, you should probably ask separate questions.

Upvotes: 1

Related Questions