Bash scripting missing ’]’

If you have the sim­ple script like the following :

#!/bin/bash
if [ $foo = 'bar']; then 
    echo 'Foo is equal to bar'
fi

And when you run the script, if you get the Miss­ing ’]’ error it means you are miss­ing a space.

The fol­low­ing script should solve your issue. Note extra space after ‘bar’

#!/bin/bash
if [ $foo = 'bar' ]; then 
    echo 'Foo is equal to bar'
fi

You may also like...