-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SC2332
Vidar Holen edited this page Apr 8, 2025
·
1 revision
Or "[ ! -a file ] is always true because -a becomes logical AND. Use -e instead."
if [ ! -o braceexpand ]
then
..
fiif [[ ! -o braceexpand ]]
then
..
fior
if ! [ -o braceexpand ]
then
..
fiBash interprets [ ! -o opt ] as [ "!" ] || [ "opt" ] instead of negating the condition. As a result, the condition is always true.
Avoid this by using [[ ! -o opt ]] or ! [ -o opt ].
The same issue applies to [ ! -a file ], but this is easier fixed using POSIX standard [ ! -e file ].
None.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!