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:30:00 GMT |