[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [SAGE] Shell programming conundrum
On Fri, Aug 02, 2002 at 12:36:46PM -0400, Adam S. Moskowitz mailed:
> Normally, I consider myself an expert in shell programming, but this one
> really has me stumped . . .
>
> Consider the following excerpt of code:
>
> : ${foo:=${foo}} # <== THIS ONE!
>
> Yes, it's legal shell code. Yes, it works (for a very broad definition
> of "work").
>
> We don't know the value of "foo"; I claim it doesn't matter.
>
> Here's the challenge: Tell me what purpose the line marked "THIS ONE!"
> serves. I claim you can delete that line and the script will produce the
> same exact results -- but I'd love for someone to prove me wrong.
I have to agree with your conclusion,
the ${foo:=bar} expantion says that if foo is unset or null, the set foo=bar.
So in the above code if foo is set, we use that value, if foo is unset or null
then we assign it the value off ... foo, which is unset or null.
I've known people who write shell like this. I've never liked assigning them
projects.
--
Bryan C. Andregg
http://www.loopback.net
gpg 1024D/24BF71A9 D862 18C1 0B31 E09E 1180 D8DC 8FDA 4497 24BF 71A9
PGP signature