Skip to main content
edited tags
Link
muru
  • 78.1k
  • 16
  • 213
  • 319
Source Link
HappyFace
  • 1.7k
  • 14
  • 29

What's the idiomatic way of returning an array in a zsh function?

I have this function,

rpargs () {
    local i
    args=()
    for i in "$@"
    do
        test -e "$i" && args+="$(realpath --canonicalize-existing -- "$i")"  || args+="$i"
    done
}

And I want to return args. The only ways I can think of are either to printf '%s\0' and then split it via expansion flags (0@), or to use a global like the code above.