Basic tips
- Use
for …;{ …;} instead of for …;do …;done
- Use
$[…] instead of $((…)) for arithmetic expansion
- Try to use
&& or || instead of if
: is a short command that does nothing
history -p prints each argument on a new line
- Unset variables evaluate to 0 in arithmetic expressions
Parameter expansion
Parameter expansion is useful to get or replace substrings, get the length of values or change the case of strings.
a="Hello, World!"
echo ${a:0:5} # Hello
echo ${#a} # 13
echo ${a//o/O} # HellO, WOrld!
echo ${a@U} # HELLO, WORLD!
echo ${a@L} # hello, world!