I've seen something along the lines of
if ! some-command; then
#do something
fi
What's the effect of the exclamation point? I see that if you use brackets, it can be used for negation.
Is that the same effect here?
I've seen something along the lines of
if ! some-command; then
#do something
fi
What's the effect of the exclamation point? I see that if you use brackets, it can be used for negation.
Is that the same effect here?
As documented in man bash
:
If the reserved word
!
precedes a pipeline, the exit status of that pipeline is the logical negation of the exit status as described above.
Correct.
Here is a code sample:
anny ~> if ! grep $USER /etc/passwd
More input> then echo "your user account is not managed locally"; fi
your user account is not managed locally
anny > echo $?
0
anny >
Source: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html