Table of Contents
BASH methods infrequently but regularly used
Here are some things that I don't use often enough to memorize, yet seem to be looking-up every few months.
Formatting a number
To force a number to be base-10 and space-pad it to five places:
printf "\nLinks copied\t\t%5d\n" $(( 10#$copyCount ))
Use ā%05dā to zero-pad the number.
Arithmetic
To increment a counter ā several methods, take note where the variable is and is not prefixed with a dollar-sign:
(( z += 1 )) z=$(($z+1)) z=$((z+1)) let z=z+1 z=`expr $z + 1`
Modulo
a=`expr 5 % 3`
Comparison
b=`expr $a \> 10` b=`expr $a \<= 10` b=`expr $a = $c`
Strings
Length of a string
b=`expr length $a`