I’m trying to compare an argument in bash under OSX using the following code…
#!/bin/bash
if ["$1" == "1"]
then
echo $1
else
echo "no"
fi
But I keep getting the following error
$bash script.sh 1
script.sh: line 3: [1: command not found
no
How do I stop it from trying to evaluate “1”?
[is a test command, so you need a space between[and"$1", as well as a space between"1"and the closing]Edit
Just to clarify, the space is needed because
[is a different syntax of thetestbash command, so the following is another way of writing the script:Which can be further simplified to