Unix & Linux: Is there any mechanism in zsh scripts for producing a string?

  • kkramsch / 200 / Thurs, 11 Mar 2010 01:49:00 GMT / Comments (3)
  • Is there any mechanism in zsh scripts for producing a string by concatenating n copies of a substring? I'm thinking something analogous to Perl's 'x' operator, e.g.

    "a" x 5 --> "aaaaa"

    Thanks,

    Karl
    Sent from a spam-bucket account; I check it once in a blue moon. If you still want to e-mail me, cut out the extension from my address, and make the obvious substitutions on what's left.
  • Keywords:

    mechanism, zsh, scripts, producing, string, unix, linux

  • http://programming.itags.org/unix-linux-programming/101790/«« Last Thread - Next Thread »»
    1. 2004-11-15, 16:48(+00), KKramsch:
      > Is there any mechanism in zsh scripts for producing a string by
      > concatenating n copies of a substring? I'm thinking something
      > analogous to Perl's 'x' operator, e.g.
      > "a" x 5 --> "aaaaa"

      [...]

      Not as such, but there are padding expansion flags:

      print ${(l:5::a:):-}

      Left pads the empty string (${:-}) with 'a's with width "5".

      Right padding example:

      $ A=foo
      $ print ${(r:30::bar:)A}
      foobarbarbarbarbarbarbarbarbar

      for a perl-like `x' operator, you need a loop:

      var=
      repeat 5 var=a$var
      Stephane

      stephane_chazelas | Wed, 30 Apr 2008 10:39:00 GMT |

    2. KKramsch <karlUNDERSCOREkramsch...yahooperiodcom.invalid> wrote:
      > Is there any mechanism in zsh scripts for producing a string by
      > concatenating n copies of a substring? I'm thinking something
      > analogous to Perl's 'x' operator, e.g.
      > "a" x 5 --> "aaaaa"


      Not sure about Zsh, but for Bash
      http://groups.google.com/groups?sel...1...uni-berlin.de

      williampark | Wed, 30 Apr 2008 10:40:00 GMT |

    3. Thus spake KKramsch (karlUNDERSCOREkramsch...yahooPERIODcom.invalid):
      > Is there any mechanism in zsh scripts for producing a string by
      > concatenating n copies of a substring? I'm thinking something
      > analogous to Perl's 'x' operator, e.g.
      > "a" x 5 --> "aaaaa"


      echo ${(l:5::a:)}

      christian_schneider | Wed, 30 Apr 2008 10:41:00 GMT |