Reputation: 183
need some help on using printf %s
This is part of my code
getspace=`expr 50-$getlength`;
#the space is between var1 & var2
printf "%s %20s\n" "$var1" "$var2"
I want swap the value %20s with getspace result.. means if getspace is 15 for this loop it will be %15s, and if getspace is 50 for next element, it willbe %50s
How do i swap in the dynamic variable for printf
I tried and it doesnt work
printf "%s %$getspaces\n" "$var1" "$var2"
Upvotes: 0
Views: 1934
Reputation: 66
I think that the line
getspace=`expr 50-$getlength`
should be
getspace=`expr 50 - $getlength`
and then,
printf "%s %${getspace}s\n" "$var1" "$var2"
should work, as it has worked for me.
Upvotes: 0