Argument | Explanation |
---|---|
$# | Number of arguments |
$* | All arguments |
$@ | All arguments, starting from first |
$1 | First argument |
$_ | Last argument of previous command |
See: Bash Hackers Wiki
Character | Explanation |
---|---|
" " | Whitespace |
|
Variable expansion |
$(cmd) | Command substitution, returns command output |
$((expression)) | Arithmetic expansion |
'' | Literal string, special chars are ignored |
"" | String, special chars are evaluated |
\ | Escape special chars |
# | Comment |
= | Variable Assignment |
[[ ]] | Evaluate conditional expression |
! | Negate test or exit status |
>, >>, < | Redirection |
| | Pipe output to another command |
; | Command separator |
{ } | Inline group, commands inside are treated as one command |
( ) | Subshell group, commands are executed in a new process |
(( )) | Arithmetic expression, returns result |
*, ? | Globs, wildcard matches |
~ | Home directory |
& | Background command |
See: Bash Guide
Loop | Multi-Line | One-Liner |
---|---|---|
For |
for i in list; do
cmd
done
|
for i in list; do cmd; done
|
If-Else |
if [ condition ]; do
cmd
elif [condition ]; do
cmd
else cmd
fi
|
if [ condition ]; do cmd; else cmd; fi
|
While |
while [ condition ]; do
cmd
done
|
while [ condition ]; do cmd; done
|
Command | Explanation | Usage |
---|---|---|
Sed | Stream Editor - transform text |
sed -i "s/to replace/replacement/g"
|
Cut | Cut fields using delimiter |
cut -d "<delimiter>" -f "<field # to cut>"
|