[SOLVED] Breaking iteration after a given number of iterations (bash).
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Well you should think a bit more about the things you are trying to accomplish. You already have all the information you need.
1. $list is a list of stings as indicated by you
2. i must be a number if compared to one (generally)
3. break is the command to call to simply break the loop. IMHO it is never a good idea to exit an entire script from the middle of an operation like a loop.
So using this information, restructure the script so items from step 1 and 2 are the correct types.
Your post greatly helps me, alghough I'm a bit confused about your statement:
This has me concerned as your for loop will not split a single string as it stands??
If you do 'locate mimeTypes.rdf' you'll find the file names listed by locate (I mean full names) are pretty long. In the skeleton program shown in post #1, list is in fact the output of locate:
And doing 'echo $list' I can see only spaces separating the full file names, which seems correct. Was that your concern?
I do not, please, want you to believe I want the full script running correctly by your intervention. But I think the best think I can do to give you the right picture is sending you it. Here it is.
# Sobre un ejemplo de INTRO_LI.TXT de M.Garrels, 7.2.5
# Copia los archivos listados por el locate a la manera indicada en
# manual de cp, opcion --parents. Alli, full file name es, e.g.,
for i in $LIST; do
cp --parents $i /xp/borrar/
This now makes more sense. Also, be wary that is any of your paths have spaces in them that this approach will not work.
To maybe help you further (I know I am not giving you direct answers here but am trying to help you learn as opposed to just telling you the answer),
your pseudo code would look like:
set a counter equal to 0
for each item in the list
some tasks here
increase the counter
test if the counter has reached objective amount (5 in your example)
if true, exit the for loop
perform some more tasks
exit loop as all items read from list
About spaces interspersed in file names --what a fine occurrence to have provided for this! I say it ironically, I have something posted in my threads and a little thinking plus trial and error will give the answer.
I think I have now all the elements to set to work. Which is what I'll do and, in case of any doubt, but remembering
Well you should think a bit more about the things you are trying to accomplish.
I can always fall back on LQ. Really, I'm under the impression of having just left the classroom, which usually has been a good one for me. Kind regards.