In my bash script I wish to ssh into a machine, and if the machine is down, perform something within an if statement.

To check whether or not the the machine is down I have an if statement using the -ne command which I use to compare the value returned by the ssh function ($? which is 255 if the ssh was unsuccessful) and 0.

However I get the following error

line 5: [0: command not found

Here is my code


ssh blobbby

if [0 -ne $?]
    echo "ssh not succesful"

If someone can please explain what mistake I've made I would be most grateful.


A space character must follow the opening bracket and precede the closing one.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.