1

Why such a simple script does not work?

  1 for i in {1..6}
  2 do
  3     if[ "$i" -lt "3" ]
  4     then
  5         echo "a"
  6     else
  7         echo "b"
  8     fi
  9 done

or

  1 for i in {1..6}
  2 do
  3     if[ "$i" < 3 ]
  4     then
  5         echo "a"
  6     else
  7         echo "b"
  8     fi
  9 done

Err:

./test.sh: line 4: syntax error near unexpected token `then'
./test.sh: line 4: `    then'
JackWM
  • 10,085
  • 22
  • 65
  • 92

1 Answers1

13

You need a space between if and [.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365