Nidhin_toms
Nidhin_toms

Reputation: 737

Transferring the output from shell script to a variable

I have written a script so that i can read from an oracle database and display it once i run the script. Is there any way that I can transfer the result to a variable ( Eg:output ) so that I can use if for some other calculations?

$ORACLE_HOME/bin/sqlplus -s /nolog<<EOF
connect useid/password@CFQ143
set pages 0 feed off
select count (platform) from platformspecific where platform='EF';
exit
EOF

Upvotes: 1

Views: 55

Answers (2)

Nidhin_toms
Nidhin_toms

Reputation: 737

this will also work:

var=$($ORACLE_HOME/bin/sqlplus -s /nolog<<EOF
connect useid/password@CFQ143
set pages 0 feed off
select count (platform) from platformspecific where platform='EF';
exit;
EOF) 
echo $var

Upvotes: 0

Wouter
Wouter

Reputation: 1568

If your current command prints the output in the console window, you should be able to do:

VARIABLE="$($ORACLE_HOME/bin/sqlplus -s /nolog<<EOF
connect useid/password@CFQ143
set pages 0 feed off
select count (platform) from platformspecific where platform='EF';
exit
EOF)"

And print out your variable:

echo "${VARIABLE}"

Upvotes: 1

Related Questions