-
Notifications
You must be signed in to change notification settings - Fork 0
Shell scripting
Austin Kong edited this page Jul 26, 2016
·
2 revisions
Set
varname=value
Use
echo ${varname}
Naming rule [A-Za-z][A-Za-z0-9_]*
$# # Number of command-line arguments
$* # All of the positional parameters, seen as a single word. Must be quoted
$@ # Same as $*, but each parameter is a quoted string, that is, the parameters are passed on intact, without interpretation or expansion. This means, among other things, that each parameter in the argument list is seen as a separate word. Must be quoted
$! # PID of last job run in background
$- # Flags passed to script
$? # Exit status of a command, function, or the script itself
$$ # PID
if [ comparison ]; then
do stuff
elif [ comparison ]; then
do other stuff
else
do things
fi
for varname in list ; do
body
done
while [comparison ]; do
while-true statements
done
until[comparison ]; do
while-false statements
done
funcname () {
body
}
This is a collection of tips and reminders for me on how to do things. What is documented here is derived from personal experience and from all over the web (some instruction or information has been copied verbatim). Original sources are provided for some of them. I have built these up over time so it has not been documented properly until now.