What's wrong with this script

I am trying to create a script but it is giving me errors on Cygwin for the following script. Could someone tell me, what am I doing wrong?

choice=1000
echo "choice is $choice"
while [ $choice -ne 0 ]; do
echo "choice is $choice"
echo 'Please select your option:'
echo '1. Option 1'
echo '2. Option 2'
echo 'Enter the number:'
read choice
echo "choice is $choice"

if [ $choice -eq 1]; then
	echo "You selected option 1"
	choice=0
elif [$choice -eq 2]; then
	echo "You selected option 2"
	choice=0
else
	echo "You have entered a wrong choice. Please choose from the options given"
	choice=1000
fi

done
echo "Completed."

Response that I get is:
choice is 1000
choice is 1000
Please select your option:

  1. Option 1
  2. Option 2
    Enter the number:
    1
    choice is 1
    [: missing ]
    [1: not found
    You have entered a wrong choice. Please choose from the options given
    choice is 1000
    Please select your option:
  3. Option 1
  4. Option 2
    Enter the number:

I think it is not taking $choice as integer in the condition box, but i am not sure.

U missed blanks:

[ $choice -eq 2]

should be:

[ $choice -eq 2 ]

Regards

Hey thanks. That works. Can't believe the mistake, but that was an excellent pick on your side. Thanks once again.

Suggestively, you may want to use a case statement in place of the if-elif.
This would allow for expansion if required later. And it's IMHO easier to read.

That is:

choice=1000
echo "choice is $choice"

while [ $choice -ne 0 ]; do

  echo "choice is $choice"
  echo 'Please select your option:'
  echo '1. Option 1'
  echo '2. Option 2'
  echo 'Enter the number:'
  read choice
  echo "choice is $choice"

  case $choice in
  1)  echo "You selected option 1"
      choice=0 ;;
  2)  echo "You selected option 2"
      choice=0 ;;
  *)  echo "You have entered a wrong choice. Please choose from the options given"
      choice=1000 ;;
  esac

done
echo "Completed."

Hope that helps some. :slight_smile:

Cheers,
Cameron