IFS and for loops
I needed to iterate over lines in a file, and I needed to use a for loop (well, I probably could have solved it in a myriad other ways, but that’s not the point).
So I tell the for loop to do
for line in `cat myfile`; do echo $lines; done
And obviously this doesn’t work, as the IFS variable is set to space, and thus prints out each word on a separate line, instead of printing all the words in one line on lines.
So I think “oh I know, I’ll just change the IFS variable” and try:
and this turns out poorly, with the for loop now believing every “n” to be the separator and breaking words on that instead… So I try with single quotes, no joy…
Having approached and passed the point where it is taking me more time to solve this problem rather than solving the problem I was using the loop for, I stop trying and start googling, finding this post.
The solution is rather nifty actually:
There you have it.
I haven’t tried it out, but this seems like it could be useful. From that page one could also make their way to one of the projects powering Cube, namely D3, and on that page you can find one or two (or more) interesting diagram types.
And filed under “oh frak! how glad I am that I never got a paypal account!”: