As commented, the syntax you have used is more like a Microsoft Windows batch (.bat
) file than anything else. Below is a conversion to bash. To look at the syntax for read, type help read
.
The syntax for an if
statement (read man bash
or this) is confusing at first. The [[
is actually a command which does pattern matching, and a simple example is shown. The pattern can only be on the right of the =
. Note that ==
can also be used but the standard says to use =
.
Simple tests can also use the test
command, or [
. Arithmetic tests use ((
.
goto
is a four-letter word and not used in polite circles (some disagree).
#!/usr/bin/env bash
#set /p choice="Start? [y/n] "
read -p "Start? [y/n] " choice
echo "$choice"
#echo $choice$
if [[ $choice = [Yy]* ]] # Accepts y, Y, yes, Yup, etc...
then
#goto Labelyes
echo YAY # Quotes are optional, but beware embedded whitespace
#set /p goodbye="BYE"
read -p "BYE" goodbye
elif [[ $choice == "n" ]] # Only n "elif" means "else if"
then
exit
else
# What happens if neither Y nor N were given?
echo "Invalid response, exiting anyway"
fi
#I have no idea what this is supposed to be for
#if [1==1]; then exit; fi
You could use a case
statement instead, but get the if
statement understood before trying that.