You are on page 1of 1

Bash Guide

if <test-expression>; then
<commands>
elif <test-expression>; then
<commands>
else
<commands>
fi

case $var in
<pattern>) <commands>;;
*) <commands>;;
esac

[ -n $var ] //True if the length of $var is greater than zero


[ -z $var ] //True if $var is empty
[ string1 (=|!=) string2 ]
[ int1 -(eq|neq|gt|lt|ge|le) int2 ]
[ -(d|f) FILE ] //-d: true if FILE exists and a directory, -f: true if FILE
exists and a file (not a device)

* &&, || may be used between multiple <test-expression>


echo, read command
single quote (') preserves literal value inside, (") does not preserve all things
(for example variable will be expanded)

You might also like