Operating System - HP-UX
1833780 Members
2637 Online
110063 Solutions
New Discussion

Problem with "while" loop in ksh

 
Stuart Abramson_2
Honored Contributor

Problem with "while" loop in ksh

Please look at the code and output below.

This script fails with a "while" loop, but works with a "for" loop. Note in the output that the "exit 1" is executed, but the script doesn't stop. Why is that?

symbcv list > ${TEMP_FILE}
#for STD in `awk '{print $1}' ${BCVFILE}`
cat ${BCVFILE} | while read STD BCV
do
grep " $STD " ${TEMP_FILE} | grep -q Sync
# 0 = true; 1 = false
if [[ $? = 0 ]]
then
echo "ERROR: STD's in ${BCVFILE} are synched to another BCV." >> ${L
OG}
grep " $STD " ${TEMP_FILE} | grep -v " $BCV " >> ${LOG}
echo "Exiting at `date | awk '{print $4}'`." >> ${LOG}
exit 1
fi
done

check_fs
symmir -f ${BCVFILE} -sid ${SID} establish -noprompt >> ${LOG} 2>&1



read STD BCV
+ symbcv list
+ 1> /tmp/bcv_ops.tmp
+ read STD BCV
+ cat /usr/local/bin/timefinder.try/bcv_files/tr2_bcv_file
+ grep 019 /tmp/bcv_ops.tmp
+ grep -q Sync
+ [[ 0 = 0 ]]
+ echo ERROR: STD's in /usr/local/bin/timefinder.try/bcv_files/tr2_bcv_file are synched to another BCV.
+ 1>> /var/opt/timefinder/logs/bcv_ops_tr2_sync.060603-1535.log
+ grep -v 140
+ grep 019 /tmp/bcv_ops.tmp
+ 1>> /var/opt/timefinder/logs/bcv_ops_tr2_sync.060603-1535.log
+ awk {print $4}
+ date
+ echo Exiting at 15:35:12.
+ 1>> /var/opt/timefinder/logs/bcv_ops_tr2_sync.060603-1535.log
+ exit 1 <== executes but keeps on going ???
+ check_fs
+ echo vtr201
+ + ls /dev/vtr201
/dev/vtr201 not found
TEST_VOL=
+ [ -n ]
+ symmir -f /usr/local/bin/timefinder.try/bcv_files/tr2_bcv_file -sid 0421 establish -noprompt
+ 1>> /var/opt/timefinder/logs/bcv_ops_tr2_sync.060603-1535.log 2>& 1
4 REPLIES 4
Kevin Wright
Honored Contributor

Re: Problem with "while" loop in ksh

because your reading in columns probably.
VAR1
VAR2

try
VAR1 VAR2
Kevin Wright
Honored Contributor

Re: Problem with "while" loop in ksh

because your reading in columns probably.
VAR1
VAR2

try
VAR1 VAR2
Stuart Abramson_2
Honored Contributor

Re: Problem with "while" loop in ksh

No, thanks. My data is rows:
019 13D
01A 13E
01B 13F

Dave La Mar
Honored Contributor

Re: Problem with "while" loop in ksh

Stewart -
I changed " $STD " to "$STD" in the
grep " $STD " ${TEMP_FILE} | grep -q Sync

This then worked.

Regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."