Assign large number of blanks to a variable

I want to assign large number of blanks to a variable in Korn shell. If it is a small number it is fine like if I want to assign 3 blanks I would code

var="   "

But if it is a big number say 100 blanks, what is a better way? Ultimately I will use it in printf statement

printf "%-100s\n" $var
var=$(printf "%100s" " ") && echo "length of var variable = ${#var}"

The first part assigns spaces to var, the second part is just information to show it worked.

1 Like

Thx. I realized that the length specified in % can be larger than the actual length of the variable.

That is not correct - for what we did "%100s" creates 100 spaces. No more no less. That is how printf standards say it works. BTW: "%[number]s" will get warnings from gcc, not from the shell version printf