Kaushal Shriyan | 4 Dec 2009 07:48
Picon

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
>    fubar=baz
>    if [ -z "$foo" ]; then
>        echo $fubar
>    fi
>
> because sometimes more code does *not* clarify intent. I think the
> parameter expansion has a much clearer intent--plus, it's several lines
> shorter. Too much of that sort of thing, though, and one runs the risk
> of perlizing the source code. :)
>
> --
> "Oh, look: rocks!"
>        -- Doctor Who, "Destiny of the Daleks"
>
> _______________________________________________
> Shell.Scripting mailing list
> Shell.Scripting@...
> http://www2.codegnome.org:59321/cgi-bin/mailman/listinfo/shell.scripting
>

Hi Todd,Cameron

Thanks for the explanation. At the moment, I am grasping it. If I have
questions, I will further question this ongoing email thread.

Thanks Again.

Thanks and Regards,

Kaushal

Gmane