[tex-live] Re: TeX Live UNIX shell scripts
Nelson H. F. Beebe
beebe@math.utah.edu
Tue, 16 Apr 2002 08:53:34 -0600 (MDT)
Vladimir Volovich <vvv@vsu.ru> notes that TeX Live has instances of
UNIX shell scripts with this use:
exec tex -fmt=latex ${1+"$@"}
The text
${1+"$@"}
raised a big red flag for me, because I've recently been bitten by a
shell bug on at least three systems, Apple Darwin (== MacOS X), DEC
OSF/1 4.0, and Compaq/DEC OSF/1 5.0, where exactly this syntax has
broken installations of multiple GNU packages, the most recent ones
being guile-1.5.6, grep-2.5.1, texinfo-4.2, and automake-1.6.1.
The automake developers tracked down the problem on Apple Darwin: its
/bin/sh is based on the zsh implementation of the Bourne shell, and it
parses the above text incorrectly. Inasmuch as MacOS X is starting to
get widely deployed in millions of systems, this problem is going to
be more severe, since I expect it will take a long time for Apple to
fix it. I don't even have a bug-reporting channel to them to alert
them to the problem.
The OSF/1 4.0 and 5.0 problem remains unresolved.
I've just gone back through old mail about this, and extracted these
snippets that discuss the problem [they are from me, unless otherwise
noted]:
>> ...
>> I made shell scripts of your simple tests, one for sh, one for ksh,
>> and one for bash, and then ran them on these systems:
>>
>> AMD Athlon GNU/Linux version 2.4.2-2smp (Red Hat 7.1)
>> Apple PowerPC G3 267MHz GNU/Linux 2.2.18-4hpmac (Red Hat Linux/PPC 2000 Q4)
>> Apple PowerPC G4 267MHz Darwin 5.3
>> Compaq Alpha Sierra OSF/1 5.0
>> Compaq/DEC Alpha OSF/1 4.0F
>> DEC Alpha GNU/Linux 2.2.19-6.2.1 (Red Hat 6.2)
>> HP 9000/712 HP-UX 10.20
>> HP/Intel IA-64 GNU/Linux 2.2.17-14smp (Red Hat 6.2) [via HP NUE emulator on IA-32]
>> IBM PowerPC AIX 4.2
>> IBM SP/2 AIX 4.3.2.0
>> Intel Pentium II FreeBSD 4.4-RELEASE #0
>> Intel Pentium III GNU/Linux 2.2.19-6.2.10smp (Red Hat 6.2)
>> Intel Pentium III GNU/Linux 2.4.9-13smp (Red Hat 7.2)
>> SGI Origin 200 IRIX 6.5
>> Sun SPARC GNU/Linux 2.2.19-6.2.1 (Red Hat 6.2)
>> Sun SPARC Solaris 2.7
>> Sun SPARC Solaris 2.8
>>
>> Either bash or ksh was unavailable on at least two of these systems
>> (Alpha GNU/Linux, and HP-UX).
>>
>> Here are the test scripts:
>>
>> % cat bug.sh
>> #! /bin/sh
>> set -
>> echo $#
>> set - "$@"
>> echo $#
>>
>> % cat bug2.sh
>> #! /bin/ksh
>> set -
>> echo $#
>> set - "$@"
>> echo $#
>>
>> % cat bug3.sh
>> #! /usr/local/bin/bash
>> set -
>> echo $#
>> set - "$@"
>> echo $#
>>
>> All systems EXCEPT OSF/1 4.0 and 5.0 produce
>>
>> 0
>> 0
>>
>> for the output. On those two systems, and only with sh, not with ksh
>> or bash, I get
>>
>> 0
>> 1
>>
>> ksh and bash on OSF/1 both produce the 0\n0 expected output.
>>
>> So, we have uncovered a new sh bug, or misfeature, on Compaq/DEC
>> OSF/1! sh has no version option or variable, but a grep of the
>> /bin/sh executable on OSF/1 4.0 turns up these RCS dates:
>>
>> 1995/02/14 1995/03/20 1995/04/26 1995/07/18 1995/09/06 1996/01/16
>> 1996/09/27 1997/06/04 1997/06/17 1997/07/22 1998/10/22
>>
>> The same action on OSF/1 shows these dates:
>>
>> 1995/02/14 1995/03/20 1996/04/30 1997/04/03 1997/06/04 1997/06/17
>> 1997/08/11 1997/11/07 1998/04/28 1998/10/22 1998/11/24 1999/02/12
>> 1999/05/13
>> ...
>> ...
>> The shell bug can be demonstrated with this script:
>>
>> % cat ~/bug4.sh
>> #!/bin/sh
>> set -
>> echo $#
>> set - ${1+"$@"}
>> echo $#
>>
>> On a system with a correctly-working shell, the output is
>>
>> % ~/bug4.sh "one" "two words" "three words here" "1 2 3 4"
>> 4
>> 4
>>
>> On Apple Darwin, the quotes are lost, producing incorrect output:
>>
>> % ~/bug4.sh "one" "two words" "three words here" "1 2 3 4"
>> 4
>> 10
>>
>> The O/S version is:
>>
>> % uname -a
>> Darwin darwin.math.utah.edu 5.3 Darwin Kernel Version 5.3: Thu Jan 24 22:06:02 PST 2002; root:xnu/xnu-201.19.obj~1/RELEASE_PPC Power Macintosh powerpc
>>
>> This error is NOT the fault of texinfo, but probably should be noted
>> in the texinfo release notes.
>> ...
This proposed fix came from an automake developer:
>> ...
>> egrep looks like
>>
>> #!/bin/sh
>> exec grep -E ${1+"$@"}
>>
>> but /bin/sh is Zsh and it will split all words in ${1+"$@"}.
>>
>> (See http://www.zsh.org/mla/workers//2002/msg00546.html for the details.)
>>
>> In other words
>>
>> % fgrep 'foo bar' /dev/null
>>
>> will certainly complain that it doesn't find the file `bar'.
>>
>> You can fix it by rewriting egrep as
>>
>> #!/bin/sh
>> exec grep -E "$@"
>>
>> on this host; or maybe more portably as
>>
>> #!/bin/sh
>> if test -n "${ZSH_VERSION+set}"; then
>> exec grep -E "$@"
>> else
>> exec grep -E ${1+"$@"}
>> fi
>>
>> ...
On Apple Darwin, /bin/sh reports
ZSH_NAME=sh
ZSH_VERSION=3.0.8
I found a variant of the above code that seems to work on Apple
Darwin:
% cat ~/bug5.sh
#!/bin/sh
set -
echo $#
if test -z "${ZSH_VERSION}"; then
echo sh branch...
awk 'BEGIN{for(k=0; k <= ARGC; ++k) print "argv[" k "] = [" ARGV[k] "]"; exit(0)}' ${1+"$@"}
else
echo zsh branch...
awk 'BEGIN{for(k=0; k <= ARGC; ++k) print "argv[" k "] = [" ARGV[k] "]"; exit(0)}' "$@"
fi
echo $#
% ~/bug5.sh "one" "two words" "three words here" "1 2 3 4"
4
zsh branch...
argv[0] = [awk]
argv[1] = [one]
argv[2] = [two words]
argv[3] = [three words here]
argv[4] = [1 2 3 4]
argv[5] = []
4
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- Center for Scientific Computing FAX: +1 801 585 1640, +1 801 581 4148 -
- University of Utah Internet e-mail: beebe@math.utah.edu -
- Department of Mathematics, 110 LCB beebe@acm.org beebe@computer.org -
- 155 S 1400 E RM 233 beebe@ieee.org -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe -
-------------------------------------------------------------------------------