Skip to content

Instantly share code, notes, and snippets.

@mattak
Created April 8, 2013 00:20
Show Gist options
  • Save mattak/5333258 to your computer and use it in GitHub Desktop.
Save mattak/5333258 to your computer and use it in GitHub Desktop.
ruby like command line string formatter.
#!/bin/sh
#
# ljust
#
# ruby like command line string formatter.
#
#
# usage:
#
# ljust [num]
#
function rep() {
n=$1
str=$2
ret=""
i=0
while [ $i -lt $n ]; do
ret="$ret$str"
(( i = $i + 1 ))
done
echo "$ret"
}
if [ $# -lt 1 ]; then
echo "usage: ljust [num]"
exit 0
fi
REPEATS=$1
PADDING=`rep $REPEATS " "`
while read line ; do
echo "$PADDING$line"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment