[LWN Logo]

Date: Sat, 4 Apr 1998 17:29:42 -0800
From: Ted Powell <ted@eslvcr.fireplug.net>
To: Raymond Rusk <rrusk@UVic.CA>
Subject: Re: RealAudio and Netscape4

Netscape versus the arithmetic command:

        sh: -c line 1: missing closing `)' for arthmetic expression sh: -1
        line 1: syntax error near unexpected token `;' sh: -c line 1:
        `((/usr/local/bin/rvplayer /tmp/MO34B2F4B209B0136.ram); rm /tmp/\
        MO34B2F4B209B0136.ram )&'

Many installations using the Korn Shell link /bin/sh to /bin/ksh.
Similarly, many installations using Bash link /bin/sh to /bin/bash.

ksh and newer versions of bash implement the arithmetic command:
    ((expression ))

These two items result in the problem cited above, and in confusion
among people who are not familiar with the arithmetic command.

On Sat, Apr 04, 1998 at 02:26:22PM -0800, Raymond Rusk wrote:
> On Sat, 4 Apr 1998, Ted Powell wrote:
> > The root of the problem is that when Netscape attempts to invoke a
> > helper application it generates a string containing '(('. For any shell
> > that implements the Arithmetic command, '((' constitutes the beginning
> > of such a command (not Netscape's intention, of course), and must be
> > matched by a closing '))'.
> >
> > The long-term solution is for Netscape to use '( (' instead of '((',
> > which will not lose them compatibility, and will gain them compatibility
> > with shells that implement the Arithmetic command.
> > 
> > The short-term solution is for you to change your implementation of
> > /bin/sh (not to be confused with /bin/bash).
> > [...description of pointing the symbolic link at another shell omitted...]
> 
> Good point.  I already invoke netscape from a script that sets up
> environment variables.  I could make sure that /usr/local/bin/ appears
> before /bin in my PATH and then link /bin/ash to /usr/local/bin/sh.
> However, the binary hack was quick and clean and it got the job done.
> 
> Thanks for explaining the real problem.

The binary hack at
    http://www.eklektix.com/lwn/1998/0212/netbash.html
(which I hadn't seen before) does in fact address the real problem,
by editing Navigator to use '( (' instead of '(('.

The author of the hack doesn't seem to completely understand the
situation, as he writes "The insertion of the first space makes `bash'
happy..." and suggests that "it is probably better to upgrade `bash'",
as if implementing the arithmetic command were some sort of bug. The
_design_ of the arithmetic command may be open to criticism for its
choice of tokens, but that was several years ago; criticism at this late
date is unlikely to have much effect.

Here is an excerpt from the sh(1) manpage at
    http://www.cs.princeton.edu/~jlk/kornshell/doc/man93.html
Note the use of the word "must".

  ((expression ))
	The expression  is evaluated using the rules for arithmetic evaluation
	described below. If the value of the arithmetic expression is
	non-zero, the exit status is 0, otherwise the exit status is 1. 
  (list ) 
	Execute list  in a separate environment. Note, that if two adjacent
	open parentheses are needed for nesting, a space must be inserted
	to avoid evaluation as an arithmetic command as described above. 

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