Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • or "${arr[@]/@()/foo.}" (with extglob) which would make it also work in ksh93 (where the ${param/pattern/replacement} operator comes from). Commented Jul 16, 2020 at 7:57
  • or "${arr[@]/+()/foo.}", or "${arr[@]/?()/foo.}" in ksh/bash, but all will fail in zsh. @StéphaneChazelas Commented Jul 18, 2020 at 18:51
  • @Isaac, @(x), +(x) and ?(x) are ksh glob operators whose zsh equivalents are (x), x## and (x|). To use those ksh glob operators in zsh, you'd set the kshglob option, though you'd probably only do that as part of the ksh emulation to interpret code intended for ksh. Commented Jul 18, 2020 at 20:07
  • @StéphaneChazelas The point is still valid: there is no portable solution. Commented Jul 18, 2020 at 20:25
  • This works, though I don't suppose it can be pushed all the way. Seems I can do it only once per expression, and it's either prefix or suffix. Otherwise I'd have to invent and maintain "names" for the locations I want to expand each array in and substitute those. Commented Jul 20, 2020 at 13:15