Been a long time since i scripted, here’s what I’m trying to do.
Have 5 inputs(or more) The person selects them on the line after starting the script, like 1 2 3 4 5, I then run that through a case statement to execute specific functions.
I had something like this but it doesn’t work, tried different args in the getopts, nothing seems to get it into the case statement.
read opt
while getopts ":1234567:" opt
do
case "$opt" in
1) print "you selected option 1" ;;
2) print "you selected option 2" ;;
3) print "you selected option 3" ;;
4) print "you selected option 4" ;;
5) print "you selected option 5" ;;
?) echo “unknown Option -$OPTARG” ; exit ;;
🙂 echo “missing required parameter for Option -$OPTARG” ; exit 1 ;;
esac
done
shift $(($OPTIND -1))
print “Your value testing $opt”
}
Tried the above code, no luck
David Quigley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.