Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: create variable with calculated number of spaces.



On Mon, May 6, 2024, at 6:38 PM, Mark J. Reed wrote:
> or, more efficiently:
>
>     printf -v spacer "%${diff}s" ''

And if the spacing is just being added to the beginning or end of
string1, then don't bother with the spacer variable:

	# Left-padded
	printf -v string1 '%*s' $#string2 $string1

	# Right-padded
	printf -v string1 '%-*s' $#string2 $string1

-- 
vq




Messages sorted by: Reverse Date, Date, Thread, Author