Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
[ -z "$ENV_VAR" -a -z "$ENV_VAR2" ]
has 2 conditions
ANDed
together using
-a
switch:
What it means is this:
-z "$ENV_VAR"
:
$ENV_VAR
is empty
-a
: and
-z "$ENV_VAR2"
:
$ENV_VAR2
is empty
btw if you're using
bash
you can refactor this condition to make it bit more succinct:
[[ -z $ENV_VAR && -z $ENV_VAR2 ]]
–
–
$ [[ -z "" -a -z "" ]] && echo Hello
bash: syntax error in conditional expression
bash: syntax error near `-a'
If used with single [
it is the "and" from test
. If used with [[
it is the file check from bash.
The bash solution:
$ [[ -z "" && -z "" ]] && echo Hello
Hello
For POSIX compatibility, [[ ... && ... ]]
is not available, but -a
is considered obsolete (and optional) by POSIX, so use two separate [
commands instead.
if [ -z "$ENV_VAR" ] && [ -z "$ENV_VAR2" ]; then