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

Re: create variable with calculated number of spaces.



On Tue, May 7, 2024 at 7:15 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> ... 'findmnt' outputs nice columns so the thing is to space the
> 'title' line accordingly -- it's mostly the mountpoint who's width
> can vary so the spacer goes in there.  Purely cosmetic.

You don't need to "cobble together complicated variables" here. Just
printf straight away to stdout.

On the occasion when you do need to justify/pad a parameter without
printing, you can use `printf -v` or this:

    % n=10
    % y=${(r:n:: :)}  # n spaces
    % x='hello'
    % z=${(r:n:: :)x}  # right-justified x

There is also l (lower-case L) for left-justification.

Roman




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