Anda di halaman 1dari 1

SHELL PROGRAMMING LOOPING

QUICK REFERENCE GUIDE FOR


for variable in file/list
do
SPECIAL CHARACTERS
command
; command separator
done
() execute commands in subshell
{} execute commands in current shell
WHILE/UNTIL
# comments
while/until test/condition
$var variable
do
& execute in the background
command
` substitute standard out
done
‘ quote all characters in a string
“ as ‘ but allow substitution
CASE
case option in
REGULAR EXPRESSIONS
option1) command;;
. match any single character
option2) command;;
$ match preceding regular expression
at the end of a line *) command;;
^ match preceding regular expression esac
at the beginning of a line (* is any non-defined option)
* match zero or more occurrences of
preceding expression IF
[] match any character in the brackets if test/condition then
(or range, i.e. 2-8) command
[^ ] match any character not in brackets elif test/expression then
(i.e., ^0-9 means non- command
numeric character) else
\\ last regular expression encountered command
\(exp\) remember expression for later fi
reference
\{m,n\} number of times occurring, with m REPETITION
\{m\} indicating minimum and n xargs -n
\{m,\} indicating maximum (see man page for more options)

COMMANDS
exit code VARIABLE EXPANSION
Exit shell with code return code ${var} simple variable substitution
${var:=value}
break level assign default value if not defined
Escape from level of for or while loop ${var:+value}
substitute value if var is non-null
continue level ${var:-value}
Continue from level of for or while loop temporarily assign value if non-null
${var:?value}
read
issue error with value if var not set,
Read input from a file
otherwise substitute value
test
Evaluate an expression or condition

trap Compiled by Michael Oliveri (www.mikeoliveri.com)


Used for error handling Feel free to print a copy for yourself!