如何在bash数组中存储多行输出?

如何在bash数组中存储多行输出?,bash,shell,sqlplus,Bash,Shell,Sqlplus,我有一个select语句 sqlplus [credentials] select variable from table; 它返回6行,我需要将它们作为数组存储在bash数组变量中 如果变量包含空格,并且希望数组中的每一行输出都有一个元素(与输出的每一个字相反),那么还需要设置IFS。使用数组时,您可能需要使用引号: array=(`sqlplus [credentials] select variable from table;`) echo ${array[*]} SaveIFS="$

我有一个select语句

sqlplus [credentials] select variable from table;

它返回6行,我需要将它们作为数组存储在bash数组变量中

如果变量包含空格,并且希望数组中的每一行输出都有一个元素(与输出的每一个字相反),那么还需要设置IFS。使用数组时,您可能需要使用引号:

array=(`sqlplus [credentials] select variable from table;`)
echo ${array[*]}
SaveIFS="$IFS"

IFS=$'\n'
array=( $(sqlplus [credentials] select variable from table;) )
echo "${array[*]}"

IFS="$SaveIFS"