help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Anomalies with ${*}


From: Bill Gradwohl
Subject: Re: [Help-bash] Anomalies with ${*}
Date: Tue, 27 Mar 2012 12:52:16 -0600

On Tue, Mar 27, 2012 at 10:38 AM, Chet Ramey <address@hidden> wrote:
It doesn't look like anyone answered this part of the question.

> It works when IFS='' precedes read on the same line, so why not before set?

You have to look at how commands are processed, and how `read' and `set'
use $IFS.  This reference explains simple command processing:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01

Assignment statements preceding the command are saved until after word
expansion.  That means that set and read both receive the arguments as
split using whatever value IFS had before the command.  The difference
is that read actually uses $IFS to process the words it reads, while set
does not.

The other thing to take into account is that Posix specifies that
assignment statements preceding special builtins like `set' stay in
effect after the special builtin completes.  Bash doesn't do this
by default, but does when Posix mode is in effect.  You'll get different
results if you run your original code with `bash' and `sh'.

Thank you.

After thinking about why echo and read are different with respect to IFS= on their statements, I concluded that read was using the IFS and echo wasn't. Your analysis confirms it.

I think you'll appreciate that this behavior is confusing. When working with a compiled language this type of thing can't happen. With an interpreter, I realize things are different, and sometimes make things possible that would be hard to duplicate via a compiled piece of code.

It's these types of subtle things that keep tripping me up but I'm grateful that help is available.

--
Bill Gradwohl


reply via email to

[Prev in Thread] Current Thread [Next in Thread]