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

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.

docker entrypoint running bash script gets “permission denied”

“Permission denied” prevents your script from being invoked at all. Thus, the only syntax that could be possibly pertinent is that of the first line (the “shebang”), which should look like #!/usr/bin/env bash, or #!/bin/bash, or similar depending on your target’s filesystem layout. Most likely the filesystem permissions not being set to allow execute. It’s … Read more

‘which’ vs ‘command -v’ in Bash [duplicate]

Well… command is likely built in to your shell, and with the -v option will tell you how your shell will invoke the command specified as its option. which is an external binary, located at /usr/bin/which which steps through the $PATH environment variable and checks for the existence of a file. A reason to select … Read more