Basic tips
- Use
for …;{ …;}instead offor …;do …;done - Use
eval {0..n}to loop - Use
$[…]instead of$((…))for arithmetic expansion - Try to use
&&or||instead ofif :is a short command that does nothinghistory -pprints 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!