Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Last active March 30, 2024 17:34
Show Gist options
  • Save tuxfight3r/a1aff96eb52458d838e40fc3b2aefcf8 to your computer and use it in GitHub Desktop.
Save tuxfight3r/a1aff96eb52458d838e40fc3b2aefcf8 to your computer and use it in GitHub Desktop.
bash script to choose an option with dialog box
#!/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
@Claudemar
Copy link

Thank you, I'm using your script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment