web123456

The string is empty and has spaces reported an error: binary operator expected

use-zor-nWhen 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/