So I discovered that the most convenient way to pass named arguments to bash functions is via 'temporary env variables' like so: kwd_arg=1 foo
. And I want to use this to pass array variables but apparently these two features don't mix as expected & I want to know how to use them together properly.
I've tried the same syntax without a function involved & without 'temporary assignment': both worked. However when used together the array arg is treated as a plain string.
# bash func accepting an env kwd arg
foo() {
echo ${array_arg[0]}
echo ${array_arg[1]}
}
# doesn't work, array arg treated as string
array_arg=(1 2) foo
# output:
# (1 2)
#
# when set globally works surprisingly
array_arg=(1 2)
foo
# output:
# 1
# 2
# works of course
echo ${array_arg[0]}
echo ${array_arg[1]}
# output: same as above