[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [SAGE] Shell programming conundrum
On Fri, 2 Aug 2002, Adam S. Moskowitz wrote:
> Normally, I consider myself an expert in shell programming, but this one
> really has me stumped . . .
>
> ...
> : ${foo:=${foo}} # <== THIS ONE!
> ...
>
> 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.
OK, I bit.
I can see only one possible function for this line of code, but I have
absolutely no idea if it is relevant to your particular shell program.
Let's say that for *some* reason (like, say, `-u' is set) you want to
make sure that foo is `set', ie, you don't want to use an unset
variable, or more specifically, you don't want to use an unset foo.
It may or may not have been set earlier in the code (again, for *some*
reason).
So, then, the line ": ${foo:=${foo}}" would serve to set the foo
variable without changing its value if it is already set. The line
foo=
would set foo, but also set it to null. There are other ways this
could be done, eg,
: ${foo=${foo}} # no colon
or even
: ${foo=} # if foo is not set, then set it to null
and perhaps others. This all has to do with `sh' not having an
explicit equivalent of csh's `set' command.
Other possible explanation: Maybe it was a typo?
Well, you asked...
;)
Dan
--
Daniel E. Singer, System Administrator
Dept. of Computer Science, Duke University, Durham NC 27708 USA
"Non cognosco. In hoc tantum laboro."