Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: why isn't IFS=$'\n' doing what I expect it to do here?
On Mar 23, 10:01pm, TJ Luoma wrote:
}
} I don't understand why IFS=$'\n' doesn't seem to be doing what I'd expect
Um, because you're expecting the wrong thing?
(I'm pretty sure this was answered on the list not that long ago, but
danged if I can find the message.)
IFS does not affect the shell's parsing of its own script language. If
it did, all sorts of scripts would fail any time IFS were exported into
the environment.
(Below here updated slightly because Phil's answer came in while I was
typing.)
As Phil mentioned, what it DOES affect is:
- Splitting or joining of words in shell expansions/substitutions
- The interpretation of input strings e.g. via the "read" builtin
or "vared"
So as an alternative to Phil's parameter expansion trick, you can do
this:
IFS=$'\n' read -d '' -A APPS <<-\APPS
Alfred 2
Bartender
ddnsa
Fantastical
Flycut
HazelHelper
MagiCal
MenuBarFilter
Mountain
Should I Sleep
SizeUp
Trickster
APPS
(Note this returns 1 because read encounters end of file before it finds
the empty separator. Since it won't ever find the empty separator, it
may be that this should be made a special case that returns zero.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author