Bash expansion question

Chris plug.org at 2nerds.com
Wed Feb 18 16:52:34 MST 2009


On Wed, Feb 18, 2009 at 3:06 PM, Corey Edwards <tensai at zmonkey.org> wrote:
> Or rather, the IFS setting was interfering with bash showing you the
> contents of IFS.
>
>        [cedwards at pheasant ~]$ echo foo${IFS}bar
>        foo bar
>        [cedwards at pheasant ~]$ echo "foo${IFS}bar"
>        foo,bar

Wow, that hadn't occurred to me at all.  Even more nakedly:

  bash$ IFS=,
  bash$ echo $IFS

  bash$ echo "$IFS"
  ,

So IFS interferes with its own printing because during
field-splitting, bash filters IFS itself from input commands before
processing those commands.  Double-quoting suppresses the
field-splitting behavior, which makes the variable's value visible in
the echo command.  Very interesting.

Chris



More information about the PLUG mailing list