zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: Repeat argument N times?
Date: Wed, 30 Jul 2014 07:24:41 +0100	[thread overview]
Message-ID: <20140730062441.GA28091@chaz.gmail.com> (raw)
In-Reply-To: <CAB2RFrTi87pBHeQD3y_JXf2LMyVCeRLCzMF+EmF73jp_hDkdxg__46523.0247741148$1406690207$gmane$org@mail.gmail.com>

2014-07-29 23:12:34 -0400, Benjamin R. Haskell:
> Is there a built-in way to repeat an argument N times?
> 
> Brace expansion is something I fall back on too much, so I've gotten in the
> habit of using it for small values of N, e.g. with a script I use to test
> uploading files to a web app:
> 
>     upload-files file1{,,} file2{,}{,,,,} file3{,,,}
> 
> uploads 3 copies of file1, 10 copies of file2, and 4 copies of file3.
> 
> It'd be nice if I could write (something like):
> 
>     upload-files file1(N3) file2(N10) file3(N4)
> 
> Today I found myself writing:
> 
>     upload-files file1{,}{,,,,}{,}{,,,,}
> 
> And while it's nice to know I can factor 100, it'd be nicer to just write
> it.
[...]

Some (non-ideal) approaches:

   upload-file $(repeat 100 echo file1)

   upload-file file1 <Ctrl-W><Alt-1><Alt-0><Alt-0><Ctrl-Y>
   
   upload-file $(printf 'file1%.0s\n' {1..100})

   upload-file  ${=${(l:600::file1 :):-}}

-- 
Stephane


           reply	other threads:[~2014-07-30  6:28 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CAB2RFrTi87pBHeQD3y_JXf2LMyVCeRLCzMF+EmF73jp_hDkdxg__46523.0247741148$1406690207$gmane$org@mail.gmail.com>]

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=20140730062441.GA28091@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=zsh-workers@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).