Computing.Net > Forums > Unix > next iteration in loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

next iteration in loop

Reply to Message Icon

Name: pnbalaji
Date: December 4, 2008 at 05:50:52 Pacific
OS: Windows XP SP3
CPU/Ram: AMD Athlon 2 GHZ, 3
Product: Dell / DESKTOP PC
Comment:

Hi,

I am using korn script to launch an ADV+ program (a legacy language) based on certain conditions. The full script is given below.

=============================================
#!/usr/bin/ksh

scnUser=$1
scnProg=$2
while true
do
begin:
clear
tempFile="/out/uow.$$"
uid=`id -un`
tFile1="/out/"${uid}"_1.$$"
tFile2="/out/"${uid}"_2.$$"
errFile="/out/"${uid}"_$$.err"
echo $scnUser > $tFile1
tr 'a-z' 'A-Z' < $tFile1 > $tFile2
read scnUpperUser < $tFile2
rm -f $errFile 2>/dev/null
rm -f $tFile1 2>/dev/null
rm -f $tFile2 2>/dev/null
rm -f $tempFile 2>/dev/null
echo ; echo
print -n "[scnloc-$scnUpperUser]"
echo
print -n "Scan WO >"
read uow
uow_length=${#uow}
echo $uow > $tempFile
if [[ $uow = "EXIT" ]] || [[ $uow = "exit" ]]
then
exit 0
fi
if [ $uow_length -ne 13 ] ; then
echo
echo " Invalid UOW."
echo " ===================="
echo " 'Y' to Clear Error"
echo " ?"
read _getY
if [ $_getY = "Y" ] ; then
goto begin
fi
fi
echo "Program is $scnProg"
run $scnProg $scnUser $errFile < $tempFile 2>/dev/null
if [ -e $errFile ] ; then
cat $errFile
echo
echo " ==================="
echo " 'Y' to Clear Error"
echo " ?"
read _getY
if [ $_getY = "Y" ] ; then
continue
fi
fi
echo "Loging Off [$scnProg]"

=============================================

You could see that there is a goto begin in the script where the uow_length is not equal to 13. This goto is not working. Basically I want go back to the begin of the do loop and it should wait for the response for the statement "read uow". I tried continue and it doesn't seem to work either. Can some one help me how to go the begining of the loop when the uow_length is not equal to 13? I can code the remaining part of the script in the else part, but I don't wanna do that.

Thanks,
Balaji.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: December 4, 2008 at 11:15:08 Pacific
Reply:

I don't see where the problem is, but it looks like the if statement is failing. This small test script works on my Solaris 9 system:


#!/bin/ksh

_getY="Y"
if [ $_getY = "Y" ] ; then
echo "getY is Y"
fi

read uow
uow_length=${#uow}
echo $uow_length

if [ $uow_length -ne 13 ]; then
echo "Invalid UOW"
fi

Does it work on yours? if it doesn't then your problem is somewhere else.

Have you tried something like this:


if [[ ${uow_length} -ne 13 ]] ; then
echo "Invalid UOW"
fi


0

Response Number 2
Name: pnbalaji
Date: December 4, 2008 at 12:07:31 Pacific
Reply:

Hi,

My script is working fine. I figured out that I need to use "continue" statement to go back to the next iteration.

Thanks for your response.

Thanks,
Balaji.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: next iteration in loop

write log in loop - ksh script www.computing.net/answers/unix/write-log-in-loop-ksh-script/4721.html

loop through directory grep file at www.computing.net/answers/unix/loop-through-directory-grep-file-at/6903.html

URGENT! bourne shell script. www.computing.net/answers/unix/urgent-bourne-shell-script/5389.html