LeftPad in Shell (Bash)
#!/bin/bashleftPad() {SIZE=${#1}PADCHAR="."if [ ! -z $3 ]; thenPADCHAR=$3fiPAD=$(($2 - SIZE))COUNTER=0RESULT=""while [ $COUNTER -lt $PAD ]; doRESULT="$RESULT$PADCHAR"let COUNTER=COUNTER+1doneRESULT="$RESULT$1"echo $RESULT}leftPad "foo" 6 "."leftPad "1" 1leftPad "2" 2leftPad "3" 3leftPad "4" 4leftPad "5" 5leftPad "hello" 7leftPad "foo" 6leftPad "foo" 3leftPad "foobar" 3leftPad "foo" 6 "?"