1. Wiki
  2. /Computer Science
  3. /Languages
  4. /Bash

Bash

Conditionals

if [ expression ]
then
    command
fi

# or
if [ expression ]; then command; fi

You can use chaining of commands to simplify things

if [ -r ~/.profile ]; then
    source ~/.profile
fi

becomes

[ -r ~/.profile ] && . ~/.profile

or

init && configure && install && cleanup || echo Install failed

Resources