zsh-users
 help / color / mirror / code / Atom feed
From: "Mark J. Reed" <markjreed@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: create variable with calculated number of spaces.
Date: Mon, 6 May 2024 18:35:57 -0400	[thread overview]
Message-ID: <CAA=-s3wnKctjeCcYT=Wsi-NQdk906EKAzV8-0JPYj2+mvJZJFA@mail.gmail.com> (raw)
In-Reply-To: <CAA=-s3xinJ5jT+6hKMrrrF-mj-eKwA_5h_kv+J0swABkvDemJA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1056 bytes --]

Well, mixed up your var names. This is what I meant:

    spacer=$(printf "%${diff}s" '')


On Mon, May 6, 2024 at 6:33 PM Mark J. Reed <markjreed@gmail.com> wrote:

> printf "%${spacer}s" "" ?
>
> Mark J. Reed <markjreed@gmail.com>
>
>
> On Mon, May 6, 2024 at 18:04 Ray Andrews <rayandrews@eastlink.ca> 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.
>>
>>
>>

-- 
Mark J. Reed <markjreed@gmail.com>

[-- Attachment #2: Type: text/html, Size: 2396 bytes --]

  reply	other threads:[~2024-05-06 22:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 22:03 Ray Andrews
2024-05-06 22:33 ` Mark J. Reed
2024-05-06 22:35   ` Mark J. Reed [this message]
2024-05-06 22:38     ` Mark J. Reed
2024-05-06 23:02       ` Ray Andrews
2024-05-06 23:28         ` Mark J. Reed
2024-05-06 23:41           ` Ray Andrews
2024-05-06 23:57       ` Lawrence Velázquez
2024-05-07  5:14         ` Ray Andrews
2024-05-07  5:52           ` Roman Perepelitsa
2024-05-07 14:56             ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA=-s3wnKctjeCcYT=Wsi-NQdk906EKAzV8-0JPYj2+mvJZJFA@mail.gmail.com' \
    --to=markjreed@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).