Tests and Branching

There are various tests that will produce either zero (which means success or true) or not zero (which usually means failure or false). Here is an example:

if [ -f ~/.bash_profile ]; then echo "You have a .bash_profile. That's good." else echo "Crikey, mate. You don't have any .bash_profile!" fi

The command if means that what follows will set the condition to true or false. The open bracket means that what follows (up to the close bracket) is a test. the -f means that the kind of test is whether what follows is a regular file. Then we have a path to a file.

The semicolon ends the if command, so the then command begins what to do if condition was true.

The else command begins what to do if the condition was false.

The fi command (if, backwards) ends the original if command.

This page is
made possible by:

This page rendered by CodeIgniter in 0.0189 seconds.