Shell Programming Quick Reference Guide

ADVERTISEMENT

SHELL PROGRAMMING
LOOPING
FOR
QUICK REFERENCE GUIDE
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
*) command;;
at the end of a line
esac
^
match preceding regular expression
(* is any non-defined option)
at the beginning of a line
*
match zero or more occurrences of
IF
preceding expression
if test/condition then
[ ]
match any character in the brackets
command
(or range, i.e. 2-8)
elif test/expression then
[^ ]
match any character not in brackets
command
(i.e., ^0-9 means non-
else
numeric character)
command
\\
last regular expression encountered
fi
\(exp\) remember expression for later
reference
REPETITION
\{m,n\} number of times occurring, with m
xargs -n
\{m\}
indicating minimum and n
(see man page for more options)
\{m,\}
indicating maximum
COMMANDS
VARIABLE EXPANSION
exit code
${var} simple variable substitution
Exit shell with code return code
${var:=value}
assign default value if not defined
break level
${var:+value}
Escape from level of for or while loop
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 ( )
Feel free to print a copy for yourself!
Used for error handling

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go