linux poison RSS
linux poison Email

Bash Script: Create simple select menu using select statement

Here is simple bash script which creates an simple options selection menu using bash 'select' statement, fee free to modify/copy and use this script to suite your requirement.

$ cat select.sh
#!/bin/bash

# Selection menu items goes here
SELECTION="option1 option2 option3 quit"

select options in $SELECTION; do

# here using the if statements you can perform the required  operation
if [ "$options" = "option1" ]; then
    echo "You have selected $options"

elif [ "$options" = "option2" ]; then
    echo "You have selected $options"

elif [ "$options" = "option3" ]; then
        echo "You have selected $options"

elif [ "$options" = "quit" ]; then
        echo "You have selected $options"
    exit

# if something else is selected, show the menu again
else
    clear;
    echo "please select some options"

fi
done

 Output: $ ./select2.sh
1) option1
2) option2
3) option3
4) quit
#? 1
You have selected option1
#? 2
You have selected option2
#? 3
You have selected option3
#? 4
You have selected quit




0 comments:

Post a Comment

Related Posts with Thumbnails