if syntax
#!/bin/bash if [ true ]; then echo "Always true" fi # -------------------- OR -------------------- # You can also move then down as follows. if [ 1 ] then echo "Always true" fi
if else syntax
#!/bin/bash str_1="String 1" str_2="String 2" if [ "$str_1" = "$str_2" ]; then echo "Both strings are equal." else echo "Both strings are not equal." fi
if file exists
if [ -f testfile ] then echo testfile exists! fi
Reference:
http://tille.garrels.be/training/bash/ch07.html
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html