Last active
March 30, 2024 17:34
-
-
Save tuxfight3r/a1aff96eb52458d838e40fc3b2aefcf8 to your computer and use it in GitHub Desktop.
bash script to choose an option with dialog box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HEIGHT=10 | |
WIDTH=40 | |
CHOICE_HEIGHT=4 | |
BACKTITLE="Cluster Options" | |
TITLE="Select Cluster" | |
MENU="Choose one of the following options:" | |
ENV="${ENV:-dev}" | |
if [ $ENV == "dev" ]; then | |
OPTIONS=(1 "Dev Option 1" | |
2 "Dev Option 2" | |
3 "Dev Option 3") | |
elif [ $ENV == "mode" ]; then | |
OPTIONS=(1 "MODE Option 1" | |
2 "MODE Option 2") | |
elif [ $ENV == "prod" ]; then | |
OPTIONS=(1 "PROD Option 1" | |
2 "PROD Option 2") | |
fi | |
CHOICE=$(dialog --clear \ | |
--backtitle "$BACKTITLE" \ | |
--title "$TITLE" \ | |
--menu "$MENU" \ | |
$HEIGHT $WIDTH $CHOICE_HEIGHT \ | |
"${OPTIONS[@]}" \ | |
2>&1 >/dev/tty) | |
clear | |
case $CHOICE in | |
1) | |
echo "You chose Option 1" | |
;; | |
2) | |
echo "You chose Option 2" | |
;; | |
3) | |
echo "You chose Option 3" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, I'm using your script