Computing.Net > Forums > Unix > Looping - how to go back to beginni

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.

Looping - how to go back to beginni

Reply to Message Icon

Name: otherguy
Date: April 23, 2008 at 13:36:41 Pacific
OS: unix
CPU/Ram: intel
Product: ncr
Comment:

I have a little script that asks a few questions, reads the answers and then uses the answers to run an sql update. The script then exits. I would like it to go back to the beginning and start over with asking the questions again for the next record I need to update. I haven't been able to get it to do this. Here is the basic script. --Thx.
#
tput clear
echo "Enter dbname : \c"
read dbname
tput clear
echo "Enter Form name or number :\c"
read form
tput clear
echo "enter old stat :\c"
read ostat
ostat=`echo $ostat | tr '[a-z]' '[A-Z]'`
tput clear
echo "enter request number :\c"
read request
request=`echo $request | tr '[a-z]' '[A-Z]'`
tput clear

FILE="/tmp"
#
for i in `ls -d /"$dbname"`

do
cd "${dbname}"

'date' >> ${FILE}/updatetohist.log
#
echo "update f$form set stat='H' where stat='$ostat' and request='$request'"|run_sql.sh >>${FILE}/updatetohist.log
#
echo "----- \n" >>${FILE}/updatetohist.log
#
done



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: April 23, 2008 at 17:25:21 Pacific
Reply:

One way is to place your script inside of a while loop and stop the loop by some flag such as "stop":


#!/bin/sh

while true
do
echo "Enter dbname, type stop to end: \c"
read dbname
if [ "$dbname" = "stop" ]
then
break
fi
echo "$dbname"
.
.
done

Slightly OFF TOPIC: What is this for?

for i in `ls -d /"$dbname"`
do

First, this is called a UUOC. Check out this link:

http://partmaps.org/era/unix/award....

If you are trying to check if /"$dbname" is a valid directory, why don't you do this instead and lose the for loop:

if [ -d /"$dbname" ]
then
echo "$dbname is a directory"
fi


0
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: Looping - how to go back to beginni

Calculation the date www.computing.net/answers/unix/calculation-the-date/6212.html

next iteration in loop www.computing.net/answers/unix/next-iteration-in-loop/8264.html

copy lines in vi from other file www.computing.net/answers/unix/copy-lines-in-vi-from-other-file/8359.html