reversing the if condition in posix shell
Am I right that 'if ! command; then ' form is not posix (the ! part?) ?
If so, then what are nice ways to reverse the condition in if ? Let's
assume the command after if is not 'test' otherwise it's easy
to reverse (test ! ...). I know several ways but none of them satisfy
me:
1. mytestcmd; if test $? != 0; then body; fi
sometimes i don't like that it adds extra line
2. if mytestcmd; then : nothing; else body; fi
adds 2-3 extra lines
3. mytestcmd || body
sometimes fine, sometimes I just prefer the 'if' form
4. if ! mytestcmd; then body; fi
i suspect this is not posix ????
5. if test `mytestcmd; echo $?` != 0; then body; fi
invokes extra subshell
Yakov
|