Traduisez - Übersetzen - Traduzca - Traduza - Tradurre - Translate

Re: Diagnosing "helper app spawn" errors with Netscape 4

Ted Powell (ted@eslvcr.fireplug.net)
Tue, 24 Mar 1998 11:33:14 -0800

On Tue, Mar 24, 1998 at 10:33:48AM -0800, Curt Sampson wrote:
> On Tue, 24 Mar 1998, Ted Powell wrote:
> [...]
> > Note that shell variables inside either ((...)) or $((...)) don't need a
> > dollar sign.
>
> Actually, it's probably safer to put it in there, however, as some

I think that the reason you're able to get away with putting a dollar
sign in front of the variable name is that ordinary textual variable
substitution is happening before the arithmetic evaluator sees the
expression. For example:

bash-2.00$ a=2
bash-2.00$ echo $(( ${a:+7} ))
7
bash-2.00$

Even though a contains 2, the variable substitution delivers 7, so what
is really being arithmetically evaluated is echo $(( 7 )) which does
not have any dollar signs in the expression.

You can cause a dollar sign to appear in the expression by using
indirection, and demonstrate that the arithmetic evaluator doesn't like
dollar signs:

bash-2.00$ a=6
bash-2.00$ echo $a
6
bash-2.00$ b='$a'
bash-2.00$ echo $b
$a
bash-2.00$ echo $(( b ))
bash: $a: syntax error: operand expected (error token is "$a")
bash-2.00$ c=a
bash-2.00$ echo $(( c ))
6
bash-2.00$

> modern shells (such as ash, which is used as a replacement for
> `standard' /bin/sh, and I think the Single Unix Specification sh)
> don't support the syntax without a dollar sign before the variable.

I guess that the ash which comes with Red Hat 5.0 isn't all that modern:
$ rpm -q ash
ash-0.2-10
A couple of experiments and a quick scan of the man page suggest that it
doesn't support $((...)) or ((...)) at all:
$ ash
$ echo $(( 2 + 2 ))
2: not found

$ (( 2 + 2 ))
2: not found
$

> Does anyone know what POSIX (in particular, IEEE 1003.2b) says
> about this?

Haven't been able to find anything on this yet.

-- 
ted@psg.com  http://psg.com/~ted/  (Ted Powell)
Promote Responsible Net Commerce: Fight Spam! http://spam.abuse.net/