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

Re: create variable with calculated number of spaces.



printf "%${spacer}s" "" ?

Mark J. Reed <markjreed@xxxxxxxxx>


On Mon, May 6, 2024 at 18:04 Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
So I want to adjust the length of string1. I do this  by inserting a spacer in string1 who's length is calculated from the length of string2:

    local diff spacer
    (( diff = $#string2 - 76 ))
    for (( dd=1; dd<diff; dd++ )); do spacer+=' '; done
    ... # spacer will be incorporated into string1, not shown.

It works fine, but I'll bet there's a less laborious way -- some way of creating 'spacer' with  'diff' number of spaces without the for loop.  I could make 'spacer' too long and then cut it at an index [diff], but I doubt that's as simple as it could be.  I know it's there, I just can't quite remember. 




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