LeftPad in Shell (Bash)

Press + to interact
#!/bin/bash
leftPad() {
SIZE=${#1}
PADCHAR="."
if [ ! -z $3 ]; then
PADCHAR=$3
fi
PAD=$(($2 - SIZE))
COUNTER=0
RESULT=""
while [ $COUNTER -lt $PAD ]; do
RESULT="$RESULT$PADCHAR"
let COUNTER=COUNTER+1
done
RESULT="$RESULT$1"
echo $RESULT
}
leftPad "foo" 6 "."
leftPad "1" 1
leftPad "2" 2
leftPad "3" 3
leftPad "4" 4
leftPad "5" 5
leftPad "hello" 7
leftPad "foo" 6
leftPad "foo" 3
leftPad "foobar" 3
leftPad "foo" 6 "?"