Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 clearFILE="/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

One way is to place your script inside of a while loop and stop the loop by some flag such as "stop":
#!/bin/shwhile true
do
echo "Enter dbname, type stop to end: \c"
read dbname
if [ "$dbname" = "stop" ]
then
break
fi
echo "$dbname"
.
.
doneSlightly OFF TOPIC: What is this for?
for i in `ls -d /"$dbname"`
doFirst, 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

![]() |
![]() |
![]() |

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