I cannot seem to figure out how to make this loop pause for user selection. It automatically chooses the * selection every time. What am I doing wrong?
#!/bin/bash
while read -r lineIn; do
if [[ "$(cmd_output)" != "" ]]; then
echo "choose one letter (a)(b)(c)(d)(e)"
read abcde
case $abcde in
[aA] ) do stuff and continue the loop;;
[bB] ) do stuff and do not continue the loop;;
[cC] ) do other stuff and continue the loop
[dD] ) do nothing and continue the loop;;
[eE] ) exit;;
* ) echo "Danger Will Robinson!";;
esac
else
echo "No output from command!"
fi
done < filename
read -p? I think justread abcdeshould work. 2. constructs like[a | A]"boil" down to[aA |], so I think you really just need[Aa](etc). Otherwise, looks good. Good Luck!-poption is because I originally thought it would pause to prompt for user input. But you are right, it is unnecessary.ksh, thereadman page shows that-pis to "Read from the current co-process instead of standard input. An end of file causes read to disconnect the co-process so that another can be created.", but it may be different forbash(too tired to look right now). Good luck.*every time because there are nobreakcommands at the end of the choices within the loop.breakcommands at the end of the choices didn't stop the loop from running unlessbreakwas on the*choice. But doing that breaks out of the entire script. And it would automatically run any command found for choice*which could be really bad. Martin's answer has fixed the issue I was having. Withread abcde < /dev/ttyit waits for one the choices to be entered. But alsobreakis needed now that it works.