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!
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I just read from somewhere that if I had IFS set to be colon (i.e. 'IFS=:'), then the string "a:b:: c d "(2 spaces in between 'c' and 'd') would be separated into 4 fields, namely "a","b",""," c d ", which is quite obvious. However, it then said that if IFS was changed to be colon and space (i.e. 'IFS= :'), then the leading and trailing space of the string would be ignore and consecutive spaces would function as a separator as well; therefore, the same string, "a:b:: c d ", would be separated into 5 fields, "a","b","","c" and "d", but I think that it should be 6 fields, "a","b",""(this null character field is the one in between the two colons), ""(this null character field is the one in between the colon and the space, which is now a separator),"c","d". Which one is correct?
Sad to say, but irrelevant of what you may think, if you set IFS as described with that input you cannot argue with the output. So there is no question on which is correct.
So I think the part of man that explains what you see is in red below:
Code:
Word Splitting
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.
The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words using these characters as field terminators. If IFS is unset, or its value is
exactly <space><tab><newline>, the default, then sequences of <space>, <tab>, and <newline> at the beginning and end of the results of the previous expansions are ignored, and any sequence of IFS
characters not at the beginning or end serves to delimit words. If IFS has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the beginning and
end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character). Any character in IFS that is not IFS whitespace, along with any adjacent IFS whitespace
characters, delimits a field. A sequence of IFS whitespace characters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs.
Sad to say, but irrelevant of what you may think, if you set IFS as described with that input you cannot argue with the output. So there is no question on which is correct.
[/code]
This reminds me of my Electrodynamics professor who once said the same to me, but as I am very so often nowhere near uncovering or discerning the truth, what else can I do but have my superficial thoughts expressed and consult the experts so that I can learn from my mistakes.
Anyway, thanks for replying. It really clears up my doubts, and I really appreciate it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.