Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to make a Bash Script that has 4 choices and prompts the user to select an option. Each option corresponds to a Linux Command operation. Can someone give me a bash example on how could this be implemented?

Thanks.

share|improve this question
    
Check help read –  heemayl Mar 25 at 12:53
    
... I would suggest help select as well –  steeldriver Mar 25 at 12:55
    
...or man dialog –  Warren Young Mar 25 at 13:16
    
A menu with the options in another file is given in unix.stackexchange.com/questions/38200/… –  Walter A Mar 28 at 21:09

1 Answer 1

Simple user selection example:

#!/bin/bash

do_exit=0

while [[ $do_exit == 0 ]]; do

    echo
    read -s -n1 answer

    case $answer in
        'l' )
            ls -l
            ;;
        'm' )
            free
            ;;
        'd' )
            df
            ;;
        'q' )
            do_exit=1
            ;;
        *)
            echo 'Invalid selection'
            ;;
    esac

done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.