If/Else in Shell Script/Bash

Really dumb question here, but this is my code:

while true
do
  read -p ">>>>" com
  if [[$com -eq "ok"]]
  then 
    echo "Good"
  else
    echo "Bad"
  fi
done

When you type ok it should say Good and if you type anything else it will say Bad. However, when I run it and type ok, this it comes out like this:

sg.sh: line 13: [[ok: command not found
Bad

change -eq to =, and make sure there is a space around the equal sign

while true
do
  read -p ">>>>" com
  if [ $com = "ok" ]
  then 
    echo "Good"
  else
    echo "Bad"
  fi
done

is the code you need

try now

1 Like

Screenshot 2020-05-12 at 9.53.13 AM
Odd, it still seems to be giving me an error.

Thank you so much!! It works!

1 Like