4

I am writing a shell script for a file, it gives me this error:

I am quite certain that the syntax is correct. I dont know what the error is

if[ "$check" = "rename" ]; then
      echo "now "
else
      echo "blub"
fi

I know its a duplicate question. I have tried this(Alternative section of the first solution) as well. :(. It still does not work for me

Community
  • 1
  • 1
user1524529
  • 897
  • 3
  • 10
  • 12

3 Answers3

9

You are missing a space after the keyword if.

if [ $check == "rename" ]; then

should work.

jman
  • 11,334
  • 5
  • 39
  • 61
1

I got this kind of error when I accidentally ran a script with #!/bin/sh instead of #!/bin/bash.

Lenar Hoyt
  • 5,971
  • 6
  • 49
  • 59
0

The answer from @Lenar Hoyt led me to the solution of similar problem. In my case I had accidentally inserted space in the very beginning of the script, so instead of

#!/bin/bash

I had

 #!/bin/bash

...so probably "wrong" shell was used. As soon as I removed the space, it worked.

Kristjan Adojaan
  • 527
  • 7
  • 10