Re: Parameter Expansion
On Fri, Dec 4, 2009 at 11:34 AM, Todd A. Jacobs <nospam@...> wrote:
> On Fri, Dec 04, 2009 at 01:07:47PM +1100, Cameron Simpson wrote:
>
>> Well, technically these last two are a little different in that they
>> change $foo.
>
> You're absolutely right. To be fair, I mentioned that ":-" substituted
> without assignment, but in retrospect the way I said it probably wasn't
> any clearer than the manual itself. Thanks for clarifying!
>
>> And once you have the ${foo} syntax, you then have some syntactic
>> scope you didn't have before, because you have room to put in all
>> sorts of stuff after "${foo" before the closing "}". And that's when
>> you get all these handy syntaxes like ${foo:-bar} and so on to get
>> various results.
>
> This is a great explanation.
>
> Of course, you can do some really non-intuitive things with these
> constructs, too:
>
> $ foo=bar
> $ fubar=baz
> $ echo ${foo:+$fubar}
> baz
>
> Generally, I think clarity should be more important than saving a few
> lines of code. Somehow, though, I just couldn't bring myself to do this:
>
> foo=bar
(Continue reading)