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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 '15 at 12:53
    
... I would suggest help select as well – steeldriver Mar 25 '15 at 12:55
    
...or man dialog – Warren Young Mar 25 '15 at 13:16
    
A menu with the options in another file is given in unix.stackexchange.com/questions/38200/… – Walter A Mar 28 '15 at 21:09

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.