Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why this script cannot loop?

Status
Not open for further replies.

bendan

IS-IT--Management
Aug 20, 2004
5
0
0
AU
under bash<br>
this script:<br>
<br>
no=0<br>
while [ $no -lt 3 ]<br>
do<br>
exec somecommnads &gt;& somefile<br>
no=`expr $no + 1`<br>
done<br>
<br>
it won't loop. it will only execute somecommands once and jump out. Without exec, the output can't be redirected to somefile.<br>
<br>
many thanks in advance
 
<br>
In ksh you _can_ use exec to open a new file for output, but you don't have to. I suspect that bash is similar. The syntax you used starts a new process, and exits the old one so it can never loop. Try again without the exec.<br>
<br>
somecommand &gt;somefile 2&gt;&1 # put stdout and stderr in somefile<br>

 
Or you can try<br>
<br>
while [ $no -lt 3 ]<br>
do<br>
( some_commands ) &gt; redirection_file &2&gt;1<br>
no=`expr $no + 1`<br>
done<br>
<br>
I hope it works...<br>

 
I have never used bsh but in most shells if you run with -x it will show you what the script is doing and indicate where the problem lies. <p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top