From: Dr. David Kirkby on
I work on a project which has this bit of code:

${gapver:=$SAGE_ROOT/spkg/standard/newest_version gap}
GAP0=`$gapver`

SAGE_ROOT will be an absolute path, so $SAGE_ROOT/spkg/standard/
newest_version is a program which takes an argument which in this case
is "gap".

Someone has said:

"The meaning of ':=' there is to only set $gapver to $SAGE_ROOT/
spkg/.... if
$gapver was unset or null previously.
"

Is that POSIX compliant? Can anyone tell me who this can be written
more portably so it runs with the default shell on Solaris, whilst not
breaking elsewhere?

Dave


From: pk on
Dr. David Kirkby wrote:

> I work on a project which has this bit of code:
>
> ${gapver:=$SAGE_ROOT/spkg/standard/newest_version gap}
> GAP0=`$gapver`
>
> SAGE_ROOT will be an absolute path, so $SAGE_ROOT/spkg/standard/
> newest_version is a program which takes an argument which in this case
> is "gap".
>
> Someone has said:
>
> "The meaning of ':=' there is to only set $gapver to $SAGE_ROOT/
> spkg/.... if
> $gapver was unset or null previously.
> "

${var:=val} sets var to val if $var is empty or unset
${var=val} sets var to val if $var is unset (but not if it's empty)

> Is that POSIX compliant?

Yes.

> Can anyone tell me who this can be written more portably so it runs with
> the default shell on Solaris, whilst not breaking elsewhere?

I think some old bourne shells support only = but not :=, I don't know what
the one you're using in Solaris does, but if you provide more details about
its version there are readers here that surely can help you.

From: Casper H.S. Dik on
"Dr. David Kirkby" <david.kirkby(a)onetel.net> writes:

>I work on a project which has this bit of code:

>${gapver:=$SAGE_ROOT/spkg/standard/newest_version gap}
> GAP0=`$gapver`


>SAGE_ROOT will be an absolute path, so $SAGE_ROOT/spkg/standard/
>newest_version is a program which takes an argument which in this case
>is "gap".

>Someone has said:

>"The meaning of ':=' there is to only set $gapver to $SAGE_ROOT/
>spkg/.... if
>$gapver was unset or null previously.
>"

>Is that POSIX compliant? Can anyone tell me who this can be written
>more portably so it runs with the default shell on Solaris, whilst not
>breaking elsewhere?


Yes and it works for the default shell in Solaris; you should note
that

${gapver:=$SAGE_ROOT/spkg/standard/newest_version gap}

will value to that expression and the shell will execute $gapver:

$ ${gapver:=echo gapver was null or not set}
gapver was null or not set

I.e., gapver is set and then it is evaluated.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
From: Sven Mascheck on
pk wrote:

> I think some old bourne shells support only = but not :=, [...]

Yes, the colon form of parameter expansion was introduced with System III ('81).
The predecessors (mainly 7th edition, traditional BSDs, Ultrix /bin/sh but not sh5)
are of historical interest (let alone that functions were not implemented, yet).
From: Thomas 'PointedEars' Lahn on
Dr. David Kirkby wrote:

> ${gapver:=$SAGE_ROOT/spkg/standard/newest_version gap}
> GAP0=`$gapver`
>
> SAGE_ROOT will be an absolute path, so $SAGE_ROOT/spkg/standard/
> newest_version is a program which takes an argument which in this case
> is "gap".
>
> Someone has said:
>
> "The meaning of ':=' there is to only set $gapver to $SAGE_ROOT/
> spkg/.... if
> $gapver was unset or null previously.
> "
>
> Is that POSIX compliant?

The syntax: yes. The statement above: no, and that is not what happens.
$gapver will be set in any case. See SUSv3, 2.6.2 Parameter Expansion:

| parameter parameter parameter
| Set and Not Null Set But Null Unset
| [...]
| ${parameter:=word} Substitute parameter assign word assign word


PointedEars