0

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

#!/bin/bash

ssh blobbby

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

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

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • This is the same question with lots of in depth answers https://stackoverflow.com/questions/4468824/command-not-found-when-attempting-integer-equality-in-bash# – generic purple turtle Oct 30 '17 at 18:04

1 Answers1

1

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

JRFerguson
  • 14,570
  • 3
  • 34
  • 40