use-z
or-n
When determining the empty value of a variable, you need to pay attention to it if you use it directly[ -n ${ARG} ]
This form,${ARG}
If there is space in it, an error will be reported.
ARG="sd dd"
if [ -n ${ARG} ]; then
echo 'ARG:' ${ARG}
else
echo 'ARG is empty.'
fi
Output:
line 27: [: sd: binary operator expected
ARG is empty.
Obviously not right
Solution, use[[ -n ${ARG} ]]
or[ -n "${ARG}" ]
refer to:
/2009/12/10/bashshell-programming-binary-operator-expected/