A lot of bash scripts have unnecessarily complex logic like the following; update them like the simpler examples:
CONVOLUTED:
# if no parameter 2:
if [ -z ${2+x} ]
then
echo "No argument 2 supplied"
fi
SIMPLER:
# if no parameter 2:
if [ -z "$2" ]
then
echo "No argument 2 supplied"
fi
CONVOLUTED:
# if _not_ no parameter 1 (in other words, if parameter 1) exists:
if [ ! -z ${1+x} ]
then
echo "Paramater 1 passed. Will assign from."
defaultValueTwo=$1
else
echo "No paramater 1 passed. Will assign default parameter."
defaultValueTwo=thing
fi
SIMPLER:
if [ "$1" ]
then
echo "Paramater 1 passed. Will assign from."
defaultValueTwo=$1
else
echo "No paramater 1 passed. Will assign default parameter."
defaultValueTwo=thing
fi
Also change e.g.
if [ ${2+x} ]
to:
if [ "$2" ]
This simpler logic has been tested on all platforms I'm involved with (Mac, Cygwin, Linux, and it doubtless works on msys2); go ahead and update all script thus.
A lot of bash scripts have unnecessarily complex logic like the following; update them like the simpler examples:
CONVOLUTED:
SIMPLER:
CONVOLUTED:
SIMPLER:
Also change e.g.
if [ ${2+x} ]
to:if [ "$2" ]
This simpler logic has been tested on all platforms I'm involved with (Mac, Cygwin, Linux, and it doubtless works on msys2); go ahead and update all script thus.
reference: - 1 - 2