我有一个包含内容的文件:
( [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
是否可以从文件中读取数组?