0

i've been doing a command line course on codecademy and i get an error that i can't figure out why it's there.

i enter this code in my script.sh file:

01 #!/bin/bash
02 first_greeting="Nice to meet you!"
03 later_greeting="How are you?"
04 greeting_occasion=0
05 
06 
07 if [$greeting_occasion -lt 1]
08 then
09   echo $first_greeting
10 else
11   echo $later_greeting
12 fi

And when i run on bash i get this:

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

I´ve tried changing greeting_occasion value but the result is always How are you? with an error on line 6. Also, i tried changing the conditional to start on line 5, and i get the same error on the same line, line 6, and the same result How are you?.

Any ideas on what´s up in this? Thank you for your time!

2

1 Answer 1

1

You need a space [ $greeting_occasion -lt 1 ].

The $greeting_occasion was transformed to a 1. this gave

if [1 -lt 1]

So bash tried to run [1, with arguments -lt, and 1] and pass its exit code to if

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .