services变量不是数组;要创建数组,需要用(...)包围该值。例如,比较一下: $ example=$(echo one two three)$ echo ${example[0]}one two three With this: $ example=( $(echo one two three) )$ echo ${example[0]}one 因此,假设$PSQL命令以适当的格式生成输出,您希望: services=( $($PSQL "SELECT array(select name from services);") ) 对于你在问题中试图做的事情,我看不出有任何理由使用array函数。给出这样一张表: CREATE TABLE services ( id serial primary key, name text);INSERT INTO services (name) VALUES ('foo');INSERT INTO services (name) VALUES ('bar');INSERT INTO services (name) VALUES ('qux'); 这样的查询将生成可修改的结果,以转换为bash数组: $ psql -t --csv -U postgres -d arraytest -c 'select name from services'f