Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to add string to end of each array element without loops
On Mar 25, 11:32pm, nix@xxxxxxxxxxxxxxxx wrote:
} Subject: How to add string to end of each array element without loops
}
} a=(1 2 3)
} a=(foo$^a[@])
}
} print -l "${(@n)a}"
If $^a[@] works, then you don't need the subscript, either:
a=(foo$^a)
Futhermore you don't need the quotes and (@) in the print expression:
print -l ${(n)a}
} foo1
} foo2
} foo3
}
} I would like to get the following output instead:
}
} 1foo
} 2foo
} 3foo
I'm not understanding what you're asking. Either this is as easy as
a=(1 2 3)
a=(${^a}foo) # braces needed to distinguish $a from $afoo
or you've already got (foo$^a) and you're asking how to change "foo?"
into "?foo" for the whole array
setopt extendedglob
a=(${a/(#b)foo(<->)/$match[1]foo})
or you mean something else entirely. Can you elaborate?
--
Messages sorted by:
Reverse Date,
Date,
Thread,
Author