Note that !
does not have a special meaning in Linux (the operating system), but in several standard programs in Linux. In your case it is not so much a feature of bash (as Mark Bramnik claimed in his otherwise correct answer), but of the standard program called test
or [
. Since bash emulates this command internally, of course it has to interpret the !
as well, but the definition can be found by doing a man test, where it is described as:
! EXPRESSION
EXPRESSION is false
Actually, bash does have a !
too, with a related, but not identical meaning. If you invoke a program by prefix it with !
, i.e.
! prog
bash sets the exit code to 0 if prog terminated with a non-zero exit code, and sets it to 1 if prog terminated with exit code zero. Therefore, you could have written
[ ! -d cc201 ]
equally well as
! [ -d cc201 ]
The overall effect is the same, but the former is the !
from test, which in turn in emulated by bash, while the latter is the builtin ststus-code negator of bash.