7

I have a select statement

sqlplus [credentials] select variable from table;

It returns 6 rows and I need to store them as an array in bash array variable.

2 Answers 2

6
array=(`sqlplus [credentials] select variable from table;`)
echo ${array[*]}
Sign up to request clarification or add additional context in comments.

Comments

5

If your variables contain spaces and you want the array to have an element for each line of output (as opposed to each word of output), you also need to set your IFS. And you may want to use quotes when using the array:

SaveIFS="$IFS"

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

IFS="$SaveIFS"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.