BASH Shell script - control block with if then else

Published: Friday, 28 November 2014
shell

Some examples.

if then else

if [ "mp3" == "$section" ]; then echo mp3 section; else echo not mp3 section; fi

or on separate lines

if [ "mp3" == "$section" ]
  then
    echo mp3 section
  else
    echo not mp3 section
fi

Check if a variable is empty

if [[ -z "$FOO" ]]
then
  echo FOO is empty
else
  echo FOO is ${FOO}
fi