I have 2 restrictions on a script I need to write.
I need to use bash shell.
I cannot generate temporary files due to permission settings on the file system.
Given those restrictions, is it possible for me to capture the standard output of a program (e.g. psql) and store each line in an array?
I know this is easily possible in korn shell, because I can simply use a pipe to direct the standard output into a loop that reads each line into the array:
psql -c "select * from some_table' |
while read LINE
(( INDEX = INDEX + 1 ))
# the following line displays data in ksh but not bash
However, it seems that bash shell spawns a new shell every time a pipe is used. In this case, the while loop runs inside a different shell... the changes to the DATA array are lost once the while loop finishes, since the spawned shell is closed.
Does anyone have a solution for this problem? (i.e. load each line of standard output into an array)