I have the following script and it works fine. Unfortunately, from user's perspective, it looks very messy because the user is able to see the output of the process caused by the print command.
\# 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" = 'RET_CODE' ]; then
read line
read line
RET_CODE=$line
fi
if [ "$line" = 'MAX_OUT' ]; then
read line
read line
CUR_MAX=$line
fi
if [ "$line" = 'PATH_OUT' ]; then
read line
read line
CUR_PATH=$line
fi
done
exec 0<&3
echo "Current Max Value is " $CUR_MAX
echo "Current Path is " $CUR_PATH
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
I am actually working on 2 scripts. The process is similar and facing the same problem.
It's funny that one of the script's update section calling the same stored procedure returning the same output parameters did not display any output on the screen. However, the other section including another script always display the "print" output on the screen. Failing to identify the difference, I copied and pasted the working section to the other section and another script. Unfortunately the problem remain. This is really weird. I had to ask a few colleagues to spot the difference but none of them were successful.
I wonder whether there is any special setting/configuration that I may have set without realising that may cause the difference. Any idea?
$ORACLE_HOME/bin/sqlplus /NOLOG >/dev/null 2>&1c @<<!
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET PAGESIZE 0
SET VERIFY OFF
Connect $DB_USER/$DB_USER_PASSWD@$DB_INSTANCE
I have just found the main cause of the problem. It's due to a simple mistake. The "echo $line" is the one that displays the data unnecessarily. It took me days trying to figure out. Should have spotted this echo earlier.
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