[vox-tech] Padding Variables in bash

Jim Angstadt vox-tech@lists.lugod.org
Sat, 12 Apr 2003 18:07:01 -0700 (PDT)


Hi All,

perl has a nice way of padding variables to line
up columns:

   print "\t$a", ' 'x($block - length($a)), "\tb:
$b \n";

Is there something similar in bash?  This hurts
my eyes:

# -----------------------------------
space_over()		# echo $1 spaces
{
	i=$1
	while (( $i > 0 )); do
		echo -n " "
		i=$(($i-1))
	done
}

wide=10
vars='abcd bcdef cdefgh defghij'

for v in $vars; do
  echo -en "\tThe length of ($v)"
  space_over "$(($wide-${#v}))"
  echo "is ${#v} and $wide minus ${#v} is
$(($wide-${#v}))"
done
# -----------------------------------

I guess I don't need to mention I'm just learning
bash.

Jim

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com