[NTLUG:Discuss] bash shell programming follies

Ken Frazer frazer at acm.org
Wed Jun 26 20:16:55 CDT 2002


Well, uhh, yes, it does once it COMPLETES the final line. In this case, it 
is executing $0 and waiting for it to finish.  Unfortunately, it doesn't 
ever finish because it spawns another copy that waits for its child to 
finish, and so on ad infinitum.  An excellent example of a classic case of 
recursion.

Try this instead:

while :
do
cat /proc/mdstat
sleep 3
done

Regards,
Ken

At 07:55 PM 6/26/2002 -0500, you wrote:
>OK, will someone explain what it was I did and why it affected my system the
>way it did?
>
>I am trying to do a fresh software RAID-1 install of Slackware 8.1.  There
>is, of course, no support for this, but I'm banging my head anyway.  During
>my adventures I decided that I wanted to watch the progress of
>"/proc/mdstat".  I went about making a bash script called loop.  (and how it
>was aptly named!)
>
>[ # loop]
>cat /proc/mdstat #show the raid device status
>sleep 3            #pause three seconds
>$0                #rerun this command
>[/ # loop]
>
>Ok...not only was I NOT able to break out of this, but when I went to
>another term screen and did a 'ps  -aux' you can imagine the humor as I saw
>hundreds of spawned '-sh' shells.
>
>I finally renamed loop to stop the loop.
>
>Does a shell script not end when it reaches the last line?
>
>-Richard
>
>
>_______________________________________________
>http://www.ntlug.org/mailman/listinfo/discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ntlug.org/pipermail/discuss/attachments/20020626/6c903b66/attachment.html


More information about the Discuss mailing list