如何将关联数组作为参数传递给函数?这在巴什有可能吗?
以下代码未按预期工作:
function iterateArray
{
local ADATA="${@}" # associative array
for key in "${!ADATA[@]}"
do
echo "key - ${key}"
echo "value: ${ADATA[$key]}"
done
}
Run Code Online (Sandbox Code Playgroud)
将关联数组传递给像普通数组这样的函数不起作用:
iterateArray "$A_DATA"
Run Code Online (Sandbox Code Playgroud)
要么
iterateArray "$A_DATA[@]"
Run Code Online (Sandbox Code Playgroud) 是否可以在bash中创建一个对象数组?
这就是我的尝试:
declare -a identifications=(
{
email = '...',
password = '...'
}
)
declare -a years=(
'2011'
'2012'
'2013'
'2014'
'2015'
'2016'
)
for identification in "${identifications[@]}"
do
for year in "${years[@]}"
do
my_program --type=CNPJ --format=XLS --identification=${identification.email} --password=${identication.password} --competence=${year} --output="$identification - $year"
done
done
Run Code Online (Sandbox Code Playgroud)
显然,这不起作用,我找不到如何实现,因为我没有找到bash对象.