Created
April 8, 2013 00:20
-
-
Save mattak/5333258 to your computer and use it in GitHub Desktop.
ruby like command line string formatter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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