Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Repeat argument N times?
- X-seq: zsh-users 19003
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Repeat argument N times?
- Date: Thu, 31 Jul 2014 17:59:26 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Fb90kEM5pU1rpHi4L8ynMfgjflVFaLKTD9E5TzJ1o+o=; b=wNpH9NpH4Fo/MMi6gnIHXEDUCcC55930wZ1A+6fcbUuc5UCxjYBTVi7on1/73buWaz tKt69z7mF4udOFRBLiZQLZoKVdS8q5ozNJOJnp1Lu2rOIDKfvCtqIUCeVBuF9VlxUKKS HwT+YjL8yNwGLNx6porG+J6aKYKEK8/QN9zxd1l+d/Ekdilyot17UW/R28AsxOPoz3yT J5a/Ub30rYFaTv8CI8rXlYIRZxk5YTGgOdr7CrvmOk9He59qp9b6MzFSwjH/MBQiCcUb Ewr6Q/sCnrWsw68HJFI4B8etZvLeXtiDlcGsjHmVRmOYJwIuesvEh3EuYwbvlSjoUuJ0 WoDw==
- In-reply-to: <140729234830.ZM20800@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAB2RFrTi87pBHeQD3y_JXf2LMyVCeRLCzMF+EmF73jp_hDkdxg@mail.gmail.com> <140729234830.ZM20800@torch.brasslantern.com>
On 30 July 2014 08:48, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Jul 29, 11:12pm, Benjamin R. Haskell wrote:
> }
> } Is there a built-in way to repeat an argument N times?
>
> Not really. You have to admit it's a rather unusual thing to do. It
> can be done by abusing other expansions, as you've discovered.
>
> } It'd be nice if I could write (something like):
> }
> } upload-files file1(N3) file2(N10) file3(N4)
>
> You can create an array of N empty elements just by assigning to the
> Nth position:
>
> N[100]=()
>
> And then:
>
> upload-files file1$^N[1,3] file2$^N[1,10] file3$^N[1,4]
>
> Works up to however much memory you're willing to waste on allocating
> empty array slots.
>
> There are other ways, e.g.
>
> upload-files file2${^${:-{1..10}}/*/}
>
> upload-files file2(e{'repeat 10 reply+=($REPLY)'})
>
> though the latter requires "file2" to actually exist, which sometimes
> might be a good thing.
Here's another minor variation on the first one,
upload-files file1${(s: :)^${(l:50:)}}
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author