Shell Scripting Cheat Sheet
Shell Scripting Cheat Sheet
Variables
| Command | Description |
|---|---|
VAR=value |
Define variable |
$VAR |
Access variable |
`command` |
Command substitution |
Flow Control
| Command | Description |
|---|---|
if |
Condition check |
then |
Execute if condition is true |
else |
Execute if condition is false |
elif |
Other conditions |
fi |
End condition check |
for |
Loop |
while |
Loop while condition is true |
do |
Loop body |
done |
End loop |
Functions
| Command | Description |
|---|---|
function_name() {} |
Define function |
return |
Return from function |
$? |
Return value of last command |
Script Control
| Command | Description |
|---|---|
#!/bin/bash |
Specify interpreter used by script |
chmod +x script.sh |
Grant execute permission to script |
./script.sh |
Execute script |