Padding characters in printf

Pure Bash, no external utilities This demonstration does full justification, but you can just omit subtracting the length of the second string if you want ragged-right lines. pad=$(printf ‘%0.1s’ “-“{1..60}) padlength=40 string2=’bbbbbbb’ for string1 in a aa aaaa aaaaaaaa do printf ‘%s’ “$string1” printf ‘%*.*s’ 0 $((padlength – ${#string1} – ${#string2} )) “$pad” printf ‘%s\n’ … Read more

Creating temporary files in bash

The mktemp(1) man page explains it fairly well: Traditionally, many shell scripts take the name of the program with the pid as a suffix and use that as a temporary file name. This kind of naming scheme is predictable and the race condition it creates is easy for an attacker to win. A safer, though … Read more

Subtract two variables in Bash

Try this Bash syntax instead of trying to use an external program expr: count=$((FIRSTV-SECONDV)) BTW, the correct syntax of using expr is: count=$(expr $FIRSTV – $SECONDV) But keep in mind using expr is going to be slower than the internal Bash syntax I provided above.