Created
January 10, 2022 12:38
-
-
Save loneicewolf/4c2919a1de6da2565b799a643a5be147 to your computer and use it in GitHub Desktop.
cases and such in bash
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
#!/usr/bin/env bash | |
## https://stackoverflow.com/questions/10376206/what-is-the-preferred-bash-shebang | |
echo -e "THIS program: $0\n" | |
## cases.sh | |
# if $# (num. of inputs) is NOT(!) EQUALS TO(=) (so, !=) 2; print "argc IS NOT 2, ..." | |
if [ $# != 2 ]; then | |
echo "argc IS NOT 2, enter IP and PORT" | |
else | |
## else we can just go with the flow | |
# I tried doing this with a "normal" 'range' like for loop which did not really work.. | |
# Creds goes to Jiaaro's brilliant idea of using seq | |
## found on StackOverflow https://stackoverflow.com/questions/169511/how-do-i-iterate-over-a-range-of-numbers-defined-by-variables-in-bash/169517#169517 | |
# thanks! | |
for i in $(seq $1 $2); do | |
echo -en "i=$i -> " | |
case "$i" in | |
1) echo "one chosen";; | |
2) echo "two chosen";; | |
*) echo "*" ;; | |
esac | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment