Bash Scripting - Conditionals - Error: Command not found

Could you please help me with an error I get when doing this exercise?

This is my code:

#!/bin/bash
first_greeting="Nice to meet you!"
later_greeting="How are you?"
greeting_occasion=0
if [ $greeting_occasion -lt 1 ] 
then 
  echo $first_greeting
else
  echo $later_greeting
fi

And this is the results in the terminal:

$./script.sh
$./script.sh: line 5: [1: command not found
How are you?

So despite the greeting occasion is zero the output is still the later greeting and I just can’t understand why.

You error message doesn’t match your code, you ran something else.

Thanks! I’ve rerun my code and it works, don’t know what I’d run the first time.

1 Like