peter cooke
peter cooke

Reputation: 999

variable has space separated values I need to get groups of 3 values for next script

I have a shell script environmental variable being populated by an sql command the sql command is returning multiple records of 3 columns. each record I need to pass to another shell script.

QUERYRESULT=`${SQLPLUS_COMMAND} -s ${SQL_USER}/${SQL_PASSWD}@${SQL_SCHEMA}<<endl
set heading off  feedback off
select col1, col2,  col3
from mytable
where ......)
order by ......
;
exit
endl`
echo ${QUERYRESULT}

outputs a single line of all columns space separated, all variables are guaranteed to be not null

 val1 val2 val3 val1 val2 val3 val1 val2 val3 ......

I need to call the following for each record

nextScript.bash val1 val2 val3

I can also run the query but count the records to determine how many times I need to call nextScript.bash.

any thoughts on how to get from a single env variable of multiple 3 parameters to my executing the next script?

Upvotes: 2

Views: 156

Answers (1)

Taoufix
Taoufix

Reputation: 372

Without the use of a variable:

( ${SQLPLUS_COMMAND} -s ${SQL_USER}/${SQL_PASSWD}@${SQL_SCHEMA}<<endl
set heading off  feedback off
select col1, col2,  col3
from mytable
where ......)
order by ......
;
exit
endl
) | while read line;do echo $line; done

Upvotes: 2

Related Questions