PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs323] nested NAME=WORD with same variable
Date: Wednesday, 21 Oct 2020, 08:31:14


    > Message Posted By: Unknown
    >
    > The spec says:
    > The expansion of WORD takes place before the substitution...
    >
    > Take ${a=${a=b}c}.
    >
    > First, I would expand the WORD ${a=b}c -> bc. Now expand ${a=bc}. Since
    > "a" already exists (a=b), I would expect the output to be "b". However,
    > the staff solution outputs "bc". Why is this?

Because the specification says earlier that

  ${NAME=WORD}  Replace by the value of the environment variable NAME, or by
		the expansion of WORD if NAME is not defined (in which case
		NAME is immediately assigned the expansion of WORD).

Thus the check for existence precedes the expansion of
WORD, which in turn precedes the substitution.

--Stan-
PREV INDEX NEXT