我有一份包含内容的文件:
( [datname]=template1 [datctype]=cs_CZ.utf-8 )
( [datname]=template0 [datctype]=cs_CZ.utf-8 )
( [datname]=postgres [datctype]=cs_CZ.utf-8 )
( [datname]=some stupid name [datctype]=cs_CZ.utf-8 )
( [datname]=jqerqwer, werwer [datctype]=cs_CZ.utf-8 )
我想阅读每一行, 并推动上下文到关联数组变量。 我无法成功使用以下代码 :
(cat <<EOF
( [datname]=template1 [datctype]=cs_CZ.utf-8)
( [datname]=template0 [datctype]=cs_CZ.utf-8 )
EOF
) |
while read r
do
declare -A row=("$r")
echo ${row[datname]}
done;
我有一个错误:
test3.sh: line 8: row: ( [datname]=template1 [datctype]=cs_CZ.utf-8 ): must use subscript when assigning associative array
可能从文件读取数组吗?