How to logically negate the return value of a command?

Chris Green cl at isbd.net
Wed Sep 24 16:09:58 UTC 2014


On Wed, Sep 24, 2014 at 04:52:38PM +0100, Colin Watson wrote:
> On Mon, Sep 22, 2014 at 07:04:57PM +0100, Chris Green wrote:
> > I want to use ping to detect if a machine is available locally on a
> > LAN as a test for a 'match exec' in ~/.ssh/config.
> > 
> > The trouble is that I need to logically negate the return value, i.e.
> > I want to have something like:-
> > 
> >     match exec "not ping -c 1 hostname"
> > 
> > However this doesn't work of course.  Is there any easy way (i.e. an
> > executable command) which will logically not the value that ping
> > returns?  I know I could write a little script that does the job but
> > if can do it without I'd be happier.
> 
> Match exec "! ping -c 1 hostname"
> 
As reported before this results in an error:-

    chris at x201$ ssh chris
    /bin/bash: line 0: exec: !: not found


-- 
Chris Green




More information about the ubuntu-users mailing list