Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: create variable with calculated number of spaces.
- X-seq: zsh-users 29919
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: create variable with calculated number of spaces.
- Date: Mon, 06 May 2024 19:57:38 -0400
- Archived-at: <https://zsh.org/users/29919>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <CAA=-s3xXX-CmL4p-oFqxFaJ0Rnz9khBirPzTdvESxsDaBiRr_g@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <8809e9e7-2389-4bb7-ba67-95222d302594@eastlink.ca> <CAA=-s3xinJ5jT+6hKMrrrF-mj-eKwA_5h_kv+J0swABkvDemJA@mail.gmail.com> <CAA=-s3wnKctjeCcYT=Wsi-NQdk906EKAzV8-0JPYj2+mvJZJFA@mail.gmail.com> <CAA=-s3xXX-CmL4p-oFqxFaJ0Rnz9khBirPzTdvESxsDaBiRr_g@mail.gmail.com>
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