Home » Category » Unix & Linux

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

200| Wed, 30 Apr 2008 10:37:00 GMT| kkramsch| 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 & Tags: mechanism, zsh, scripts, producing, string, unix, linux

URL: http://programming.itags.org/unix-linux-programming/101790/
 
«« Prev - Next »» 3 helpful answers below.
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 |

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 |

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 |

Unix & Linux Hot Answers

Unix & Linux New questions

Unix & Linux Related Categories