Skip to content

Instantly share code, notes, and snippets.

@aaron-watts
Created October 24, 2021 12:36
Show Gist options
  • Save aaron-watts/a97a93e643da332fa4c079ffc2298d18 to your computer and use it in GitHub Desktop.
Save aaron-watts/a97a93e643da332fa4c079ffc2298d18 to your computer and use it in GitHub Desktop.
No switch statement
#!/usr/bin/bash
function funsplash {
clear
echo ========================================
echo This script presents you with 2 options:
echo 1. Choose the width of your photo.
echo 2. Choose the height of your photo.
echo ----------------------------------------
read -n 1 -s -r -p "Press the 'ANY' key to continue - LOL!!!"
clear
echo =========================================
echo -e "How wide would you like your photo to be?\n\nPlease select from one of the following:"
options1=("100" "200" "300" "400" "500" "600" "700" "800" "900" "1000" "1980")
echo ${options1[@]}
while read width && ! echo ${options1[@]} | grep -q -w $width; do
clear
echo -e "Choice not valid!\n\nPlease select from one of the following:"
echo ${options1[@]}
done
echo "You have chosen $width"
read -n 1 -s -r -p "Any key to continue..."
clear
echo =====================================================
echo "Now select how high would you like your photo to be?"
PS3='Select a height: '
options2=("100" "200" "300" "400" "500" "600" "700" "800" "900" "1000" "1080")
echo ${options2[@]}
while read height && ! echo ${options2[@]} | grep -q -w $height; do
clear
echo -e "Choice not valid!\n\nPlease select from one of the following:"
echo ${options2[@]}
done
echo "You have chosen $height"
read -n 1 -s -r -p "Any key to continue..."
clear
echo "Downloading ...""
}
funsplash
@jjaimealeman
Copy link

DUDE! I have much to learn! lol

I hacked that together from several snippets I found on StackOverflow and reddit. It took me just over 2 days of Googling and testing.
You brought my file size down from 4.1k and 136 lines, down to 2.1k and 62 lines! 😮

Thank you!

@aaron-watts
Copy link
Author

Aha no worries 😅

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