You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m implementing list-ops as a library, and I've got some questions about the best way to proceed. Consider
source list_ops.sh
double() { echo$(($1*2));}
list=( 1 2 3 4 )
list::map double list # or
list::map double "${list[@]}"
Should the array be passed by name, or should the elements be passed? For a map function it doesn't really matter, but if the list function is something like intersection it would make more sense to pass 2 array names.
Also, struggling with the best way to return a result array:
the safest way is to force the user to pass an array name:
result=()
list::map double list result # in some order
printf "%s\n" "${result[@]}"
the simpler method, command substitution, is subject to word splitting and globbing: