earthbound19 / _ebDev

Various tools, mostly custom-made for art development.
2 stars 2 forks source link

Update .sh parameter/no (e.g. $1 or $2) detection in all bash scripts #27

Closed earthbound19 closed 4 years ago

earthbound19 commented 4 years ago

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.

reference: - 1 - 2

earthbound19 commented 4 years ago

DONE.