So this is more an oddity I've come up against than something I really want to use. But I found something I didn't understand with the bash extended test syntax.
Check this out (included my shell version in case it matters):
34>$SHELL --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.
35>[ ! -d /tmp ] && echo Hi
36>[ ! ! -d /tmp ] && echo Hi
Hi
37>[[ ! -d /tmp ]] && echo Hi
38>[[ ! ! -d /tmp ]] && echo Hi
39>
OK, so lines 35 and 36, using the normal test, operate as I expect. The single bang doesn't print a line (because /tmp exists), and the double bang does.
Line 37, using extended bash syntax, also doesn't print anything, as I would expect. But line 38 doesn't either! This is surprising to me; it indicates that the directory doesn't exist, but also doesn't not exist?
Searching for information on this has been frustrating. Am I missing something here? An unmentioned syntax error? I just want to understand why this happens.
!
s outside.! ! [[ -d /tmp ]]
relies only on behavior that's actually part of the test suite for the shell, whereas the historical understanding oftest
behavior referenced in answer E1 in the FAQ in bash's codebase does not require multiple!
s inside a single test to be valid (or to have any other specific/particular behavior, making the result at hand here as legitimate as any other -- ain't undefined behavior fun?). – Kodok!
doesn't bind as tightly as-o
, nothing more.[[ ! ! -d /tmp ]]
failing just looks like a bug to me;[[ ! (! -d /tmp) ]]
works correctly. – Numbatksh
does the same thing. – Ronnaronnholm