ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
I have a shell script that has a loop that passes through the lines in a file one at a time. the problem that I have is that the rsh commands inside the loop break it. some research shows that a for loop will not break with rsh commands like a while loop will. so my question is how can I best convert a loop of the form
Code:
while read line
do
stuff
done < file
to one of the form
Code:
for line in (lines of file)
do
stuff
done
this is a sh script on solaris 9. thanks in advance for your help.
that sounds good until I run it and it breaks up my absolute filenames that are in the file we are iterating through on every n using the exact syntax you gave me. its breaking my absolute filenames into 3 or 4 garbled pieces of garbage.
that sounds good until I run it and it breaks up my absolute filenames that are in the file we are iterating through on every n using the exact syntax you gave me. its breaking my absolute filenames into 3 or 4 garbled pieces of garbage.
That’s because the IFS variable can’t be set using escape sequences (at least I don’t think so). You have to actually set the variable to a newline—e.g.:
Code:
IFS="$(echo)"
With the previous setting, IFS matches either a literal backslash or a literal “n” as the field separator.
The default IFS is (iirc) (any/all of) space, tab and newline, but, as mentioned above, you have to set them literally, not via escape sequence.
Also, use single quote marks eg for newline its
IFS='
'
Of course, if the src file is just a list of absolute filenames, 1 per line, there's no need to fiddle with the IFS anyway.
looks like chrism01 wins with ignore it and the default FS works. I have a feeling I'll get stuck on something else along the way to finishing this project but for now I am set, thanks.
That’s because the IFS variable can’t be set using escape sequences
You're right, sorry! Indeed I tested on a file containing blank spaces and no n chars. I remember something about using octal codes, but not sure. I will check. Sorry again! Cheers
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.