[SOLVED] bash while loop does not execute in succession?
SlackwareThis Forum is for the discussion of Slackware Linux.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I ran the following code, containing a while loop:
while [ $i -le 2009 ]
mkdir -p /local/directory/$i
ftp -n host port <<EOF
user username password
and I noticed something strange: when I checked the local directory about half an hour after the execution of the script had started, I noticed that the folders 1989, 1990, 1991, 1992 and 1999, 2000, 2001 existed. Nevertheless, some hours later when the script finished, the local directory contained all the folders it should, and it seems that everything is ok. But how is that possible? Isn't the bash loop executed in succession, I mean, I did not expect to see some years skipped at some point during the execution of the script, as was the case with the years from 1993 to 1998?
Any suggestions will be appreciated.
Are you sure that 1999,2000,2001 weren't left behind by a previous run of your while loop? mkdir is an atomic filesystem operation. There is no way that they should show up out of sequence.
Yes, I am sure that there were no left overs, as I either delete everything or nothing. But, as I come to think about it,
I fiddled with screen a bit, and it is possible that the later directories were created by an older process I had not terminated.
Thank You for your suggestion, for me it important to know that it is not possible for a while loop in bash to run out of succession.