I keep getting this error:
./install.sh
./install.sh: line 28: syntax error near unexpected token `do'
./install.sh: line 28: ` do'
When running this code (a work in progress):
# Set the prompt string:
PS3='Choose folder: ';
function choose() {
# This works:
#select folder;
#do test -n "$folder" && echo You chose: $REPLY\) $folder && break;
#echo 'Wrong entry, try again.';
#continue;
#done;
select folder;
do
case $folder in
'q')
echo 'Exiting …';
break;
;;
*)
do
test -n '$folder' && echo You chose: $REPLY\) $folder && break;
echo 'Wrong entry, try again.';
continue;
done;
;;
esac;
done;
}
# Switch to glob folder location:
cd ~/Desktop;
# Create menu:
choose foo*;
# Do stuff with result of choose() here ...
# Exit program:
exit 0;
As you can probably see from above, I'm trying to create a menu that lets me choose from a list of globbed folders; unfortunately, I can't figure out why my nested do
is creating the error I posted above.
Optimally, the user could choose from a list of directories; if they type q
, then the program quits; if they make an invalid selection, the program makes them choose again until they pick a valid selection (or enter q
to quit/exit).
I have yet to get the quitting part figured out completely, but before I can do that, I need to get past this do
statement error.
Question: What is causing the syntax error near unexpected token `do'
and how can I fix it?