Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Warning

Make sure you have spaces inside the [] otherwise bash will sit spit the dummy!


Code Block
languagebash
themeRDark
titleCheck for Success
collapsetrue
if [ $? -eq 0 ]; then
  echo "Success"
else
  echo "Failure"

...

Code Block
languagebash
themeRDark
titleCheck for Failure
collapsetrue
if [ $? -ne 0 ]; then
  echo "Failure"
else
  echo "Success"

Conditionally Exit

Code Block
languagebash
themeRDark
titleExit with Error in 1-Line
collapsetrue
# Use braces
CARLA_TARBALL=`ls ${CARLA_ROOT}/Distd/*.tar.gz 2> /dev/null` || { echo "Carla tarball not found, exiting." ; exit 1; }

Conditionally Set Variables

Code Block
languagebash
themeRDark
titleSet if not already defined
collapsetrue
: ${var=value}

This one is obscure....<TODO> explain!

Code Block
languagebash
themeRDark
titleSet if not defined OR set to the empty string
collapsetrue
: ${var:=value}

...