1

Good evening (or day. Whichever)! I ran into a problem while writing a bash script. I have the code

#!/bin/bash
echo "Available options:"
echo "1. text"
echo "2. exit"
read var1
echo

if [[$var -ge 0]]; then
   echo "hello world"
elif [[$var -ge 1]]; then
     echo "good bye"
else
    echo "error"
fi

and all the time it puts the emphasis on the operator

./proba3.sh: line 9: [[: command not found
./proba3.sh: line 11: [[: command not found

I tried many variations of the branching operation, but still get the same error. I will be very glad for advice or hints on how to fix this error. Thanks in advance

1 Answers1

1
  1. You need spaces inside the brackets.
  2. Also you misspelled the variable name.
  3. Finally, you should probably test for equality not ge

Fixed:

#!/bin/bash
echo "Available options:"
echo "1. text"
echo "2. exit"
read var
echo

if [[ $var -eq 1 ]]; then
   echo "hello world"
elif [[ $var -eq 2 ]]; then
     echo "good bye"
else
    echo "error"
fi
Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31