Advanced Bash Shell Scripting Guide - Reference Cards
Advanced Bash Shell Scripting Guide - Reference Cards
Prev Next
Variable Meaning
$0 Name of script
$1 Positional parameter #1
$2 - $9 Positional parameters #2 - #9
${10} Positional parameter #10
$# Number of positional parameters
"$*" All the positional parameters (as a single word) *
"$@" All the positional parameters (as separate strings)
${#*} Number of command line parameters passed to script
${#@} Number of command line parameters passed to script
$? Return value
$$ Process ID (PID) of script
$- Flags passed to script (using set)
$_ Last argument of previous command
$! Process ID (PID) of last job run in background
2:32
Now Playing
Arithmetic String
Comparison Comparison
-eq Equal to = Equal to
== Equal to
-ne Not equal to != Not equal to
-lt Less than \< Less than (ASCII) *
-le Less than or equal to
-gt Greater than \> Greater than (ASCII)
*
-ge Greater than or equal to
-z String is empty
-n String is not empty
Expression Meaning
${var} Value of var, same as $var
Expression Meaning
${#string} Length of $string
Expression Interpretation
Brackets
if [ CONDITION ] Test construct
if [[ CONDITION ]] Extended test construct
Array[1]=element1 Array initialization
[a-z] Range of characters within a Regular Expression
Curly Brackets
${variable} Parameter substitution
${!variable} Indirect variable reference
{ command1; command2 } Block of code
{string1,string2,string3,...} Brace expansion
Parentheses
( command1; command2 ) Command group executed within a subshell
Expression Interpretation
Array=(element1 element2 element3) Array initialization
result=$(COMMAND) Execute command in subshell and assign result to variable
>(COMMAND) Process substitution
<(COMMAND) Process substitution
Double Parentheses
(( var = 78 )) Integer arithmetic
var=$(( 20 + 5 )) Integer arithmetic, with variable assignment
Quoting
"$variable" "Weak" quoting
'string' "Strong" quoting
Back Quotes
result=`COMMAND` Execute command in subshell and assign result to variable