-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2331
Vidar Holen edited this page Apr 8, 2025
·
1 revision
if [ -a ~/.bash_aliases ]
then
source ~/.bash_aliases
fi
if [ -e ~/.bash_aliases ]
then
source ~/.bash_aliases
fi
The POSIX standard way to check whether a file exists is [ -e file ]
.
Bash and Ksh have historically allowed using -a
, but this has no benefit and some potential downsides. For example, in Bash [ -a file ]
is true when the file exists, but [ ! -a file ]
is also true, and unconditionally so, because -a
is treated as logical "and" between non-empty strings.
Avoid the ambiguity entirely by always using the standard, portable -e
.
None
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!