[leaf-devel] inverting exit status

2004-07-05 Thread Chad Carr
Shell gurus,
Is there a reliable cross-platform way to write an inverted if 
statement?  Something like bash's:

if ! /usr/bin/false # with some other command, obviously
then
# do something true
else
# do something false
fi
Your assistance is greatly appreciated.
Chad

---
This SF.Net email sponsored by Black Hat Briefings  Training.
Attend Black Hat Briefings  Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

___
leaf-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-devel


Re: [leaf-devel] inverting exit status

2004-07-05 Thread Mike Noyes
On Mon, 2004-07-05 at 17:39, Chad Carr wrote:
 Shell gurus,

Chad,
I'm by no means a shell guru, but this Google string may help.

Google string: inverted if posix ash

 Is there a reliable cross-platform way to write an inverted if 
 statement?  Something like bash's:
 
   if ! /usr/bin/false # with some other command, obviously
   then
   # do something true
   else
   # do something false
   fi
 
 Your assistance is greatly appreciated.

I hope this is helpful.

-- 
Mike Noyes mhnoyes at users.sourceforge.net
http://sourceforge.net/users/mhnoyes/
SF.net Projects: ffl, leaf, phpwebsite, phpwebsite-comm, sitedocs



---
This SF.Net email sponsored by Black Hat Briefings  Training.
Attend Black Hat Briefings  Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

___
leaf-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-devel


Re: [leaf-devel] inverting exit status

2004-07-05 Thread Charles Steinkuehler
Chad Carr wrote:
Shell gurus,
Is there a reliable cross-platform way to write an inverted if 
statement?  Something like bash's:

if ! /usr/bin/false # with some other command, obviously
then
# do something true
else
# do something false
fi
Your assistance is greatly appreciated.
Just shuffle the then and else code around as appropriate for the 
sense of the exit condition you're checking for.

If that's not an option (ie: you're only checking one case, and don't 
want an empty then), you can do something like

  if /usr/bin/false ; [ $? -ne 0 ] ; then
...
or more typically:
  /usr/bin/false
  if [ $? -ne 0 ] ; then
...
or even:
  /usr/bin/false
  retcode=$?
  ...
  if [ $retcode -ne 0 ] ; then
...
If you're just trying to test for error codes or something, the 
following might be handy:

  abort() { ... }
  # Call an abort procedure if command1 fails
  /usr/bin/command1 || abort
  # Run several commands if command2 fails
  /usr/bin/command2 || { echo ERROR!!! ; exit ; }
HTH
--
Charles Steinkuehler
[EMAIL PROTECTED]
---
This SF.Net email sponsored by Black Hat Briefings  Training.
Attend Black Hat Briefings  Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

___
leaf-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-devel