1

I have a bash script, and I can't get the if statement to work correctly.

This is what I have so far.

#!/bin/bash
FILES = 'abc'
if ["$FILES" == "$1"]
then
    echo "ok";
fi

Why doesn't this if statement work correctly?

Eric Leschinski
  • 123,728
  • 82
  • 382
  • 321
  • Ensure you have spaces around the square brackets. They're actually a shorthand for a specific command and not brackets in the way you are used to. – borrible Jan 18 '16 at 19:30
  • 1
    I recommend you learn about [`make`](http://www.gnu.org/software/make/manual/make.html) instead, or [some other system](https://cmake.org/) of handling building for you. – Some programmer dude Jan 18 '16 at 19:33
  • 2
    http://www.shellcheck.net/ is your friend. – Etan Reisner Jan 18 '16 at 19:36
  • Thanks for all the comments. I will definitively check those. I know this is just me trying to do something and learn a little bit of bash at the same time :) –  Jan 18 '16 at 19:54

1 Answers1

1

You need spaces before and after the condition:

if [ "$FILES" == "$1" ]
   ^^               ^^

Since you are using bash, you can use bash built-in [[ and ]] instead of the test command [.

Also see: What is the difference between test, [ and [[ ?

P.P
  • 106,931
  • 18
  • 154
  • 210
  • Thanks a lot! That was the problem there was no pace after and before the brackets. –  Jan 18 '16 at 19:54