Kerry,

The 'if' construct needs spaces in the right places...


if     [         $?       -eq        0        ]         ; then




this is exaggerated, but those square brackets need a space on each side or
it don't work.





----- Original Message -----
From: "Kerry Mayes" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, April 17, 2008 12:16 PM
Subject: Re: Help with shell scripting


> Thanks Rex, yes that's a much better way of doing it.
>
> Still having difficulty though - I think its either with quotes or
> semi-colons now...
>
> As I understand it, ";" are required between statements that are in
> places where only one statement is expected.  So, keeping it to it's
> simplest form:
>
> SYNHOST=caalt04
> ping -c 1 $SYNHOST
> if [ $? -eq 0 ] ; then
>    echo "Synergy connected"
>
> else
>
>    echo "Synergy NOT connected"
>
> fi
>
> Returns:
>
> PING caalt04.caa.local (192.168.0.183) 56(84) bytes of data.
> 64 bytes from caalt04.caa.local (192.168.0.183): icmp_seq=1 ttl=64
time=0.172 ms
>
> --- caalt04.caa.local ping statistics ---
> 1 packets transmitted, 1 received, 0% packet loss, time 0ms
> rtt min/avg/max/mdev = 0.172/0.172/0.172/0.000 ms
> Synergy connected
> : not founddefault: 11: else
> Synergy NOT connected
>
> So the ping command works but the if statement doesn't - the else
> isn't recognised so it's doing both commands.

Reply via email to