In my environment, without the exec, the value stored in the variable assigned inside the while loop cannot be referred. In the code as follows, you'll get "123" instead of the value obtained from the SPOOL_FILE at the last echo statement. I have no idea why. I was struggling with this problem before discovering exec method.
CUR_MAX=123
# Reading the spool file to get stored procedure's returned values
exec 3<&0
exec 0<$SPOOL_FILE
while read line
do
echo $line
if [ "$line" = 'MAX_OUT' ]; then
read line
read line
CUR_MAX=$line
fi
done
exec 0<&3
echo "Current Max Value is " $CUR_MAX
Meanwhile, the suggestion to add "</dev/null 2>&1" in the following does not prevent print section from being displayed
$ORACLE_HOME/bin/sqlplus /NOLOG
</dev/null 2>&1 @<<!