Hi,

On Sat, Sep 16 at 06:16, Terry Coles wrote:
...
> 2.  I tried to put the command into an if structure to test to ensure that it 
> worked, eg
> 
> if [ "rdate -v 192.168.0.2" ]; then
>   exit 0
> else
>   exit 1
> fi

That's not the way to test the outcome of a command.  The [ ] actually
delimit the "test" command that performs various tests on it's arguments
before exiting with the result.  What you've coded there is a test of
whether the string "rdate -v 192.168.0.2" is non-zero length.

Skip the [] and run the command directly in the if structure.

    if rdate -v 192.168.0.2 ; then
      exit 0
    else
      exit 1
    fi

The return code of the last command is available in the variable $? so
you could simplify this to.

    rdate -v 192.168.0.2
    exit $?

Or even simpler as this is the last command.

    exec rdate -v 192.168.0.2

HTH

-- 
        Bob Dunlop

-- 
Next meeting:  Bournemouth, Tuesday, 2017-10-03 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue     / TO THE LIST OR THE AUTHOR

Reply via email to