b8zs, on Feb 3 2007, 01:26 AM, said:
tehbizz, on Feb 2 2007, 11:12 PM, said:
Still not a trick. This is explained in the manpage.
I thought the idea was just to post shortcuts we use on a daily bases to make our lives easier when working with shells (be it explained in a manual page or not).
Your "trick" is explained in a man page as well: try looking in SH(1)
Actually what I posted is not what IFS is but how to fully read spaced items correctly. Here's what man 1 sh has to say:
Quote
IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ‘‘<space><tab><newline>’’
Now, it does go on to explain that:
Quote
Any element of an array may be referenced using ${name[subscript]}. The braces are required to avoid conflicts with pathname expansion. If subscript is @ or *, the word expands to all members of
name. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${name[*]} expands to a single word with the value of each array member separated by the
first character of the IFS special variable, and ${name[@]} expands each element of name to a separate word.
Then this:
Quote
If the value of IFS is null, no word splitting occurs.
However, I didn't set it to null, I set it to newlines only. I tried null and it worked but not how I wanted it to, it globbed all array elements into a single element. And since IFS is supposed to honor shell quoting, I found this too to not work so only setting it to newlines was possible for exactly what I needed. Not only did I pour over my book on shell scripting and the Advanced Shell Scripting Guide, I read tens of posts on the web about how to do this and not one had the correct answer. Then not only did I actually consult people who've used UNIX longer than Linux has been around, I could never get a straight answer on exactly what to do because so few people ever
think about what IFS is and what it does. It's surprising how many people don't even know it exists. Most references ever made to IFS are buried in text or appendices simply because it's a forgotten element of the shell.
Using * as a delimiter in a search is the village secret everyone knows about but how to use IFS is something so few know. That's what makes it a real trick. So far, a number of the posts in this thread are merely shortcuts, not actual tricks. Perhaps "shell shortcuts" would have been a more appropriate title.