Bash Cheatsheet
Bash Cheatsheet
VARIABLES AND
SHELL EXPANSIONS
POSITIONAL SPECIAL
VARIABLES PARAMETERS PARAMETERS
VARIABLES
DEFINITION :
Variables are parameters that you can change the value of
2 TYPES OF VARIABLES
1 USER-DEFINED
VARIABLES
2 SHELL
VARIABLES
BASH SHELL VARIABLES
SETTING THE VALUE OF A VARIABLE
name=value
PATH List of directories that the shell should search for executable files
SYNTAX:
Simple Syntax: $parameter
Advanced Syntax: ${parameter}
2 ${parameter^^}
Convert all characters of the parameter to uppercase
3 ${parameter,}
Convert the first character of the parameter to lowercase
4 ${parameter,,}
Convert all characters of the parameter to lowercase
5 ${#parameter}
Note: None of these alter the value stored in the parameter. They
just change how it is displayed after the expansion.
DEFINITION :
Command Substitution is used to directly reference the
result of a command
$(command)
ARITHMETIC EXPANSION
DEFINITION :
Arithmetic Expansion is used to perform mathematical
calculations in your scripts.
$(( expression ))
ARITHMETIC OPERATORS RANKED IN ORDER OF
PRECEDENCE (HIGHEST PRECEDENCE FIRST):
Exponentiation.
**
2**4 means 2 to the power of
4, which is 16
Note: When two operators have the same precedence, the one furthest to the
left gets performed first.
THE BC COMMAND
echo “expression” | bc
Using the scale variable to control the number decimal places shown