Article View: gnu.bash.bug
Article #1109More :${abc?abc} exits
From: Jeff Barratt
Date: Fri, 05 Jan 1990 20:19
Date: Fri, 05 Jan 1990 20:19
59 lines
1973 bytes
1973 bytes
Brian,
With regard to John Ramsdell's question about parameter
expansion: The syntax
${param:?[value]}
is supposed to substitute "param" if it is not null, otherwise it
should write "value" to stderr. If value is omitted, then sh writes
param: parameter null or not set
This is paraphrased from UNIX Shell Programming, by Kochan and Wood.
As you can see from the transcript below, sh will also accept
${param?[val]} (e.g. without the internal ":"). sh only writes the
"value" string if the variable "param" is not set. If the variable is
set, sh attempts to execute the contents of param as a command.
Script started on Fri Jan 5 14:41:09 1990
bash$ sh
$ set
ARCH=sun3
BASH=/bin/sh
..
..many other variables...
..
$ echo $abc
$ ${abc?}
abc: parameter null or not set
$ ${abc:?}
abc: parameter null or not set
$ ${abc?"What a crock"}
abc: What a crock
$ ${abc?ls}
abc: ls
$ abc=
$ ${abc?}
$ ${abc?ls}
$ abc=zip
$ ${abc:?}
zip: not found
$ ${abc:?"What a crock, II"}
zip: not found
$ : ${abc:?}
$ : ${abc:?"What now?"}
$ exit
script done on Fri Jan 5 14:43:23 1990
Bash, on the other hand, doesn't seem to handle this. If abc is not
set, the syntax
${abc:?}
will exit the shell, and
${abc:?"Help"} will echo Help and *then* exit the shell. In
neither case should bash exit the current shell. If abc=ls, then bash
behaves correctly, e.g. executes ls, and remains in the current shell.
I verified this behavior in both 1.03 and 1.04 on a Sun-3 running
SunOS 4.0.3
Thanks,
Jeff Barratt
Technical Details
Message-ID:
<9001052019.AA01516@dash.mitre.org>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!DASH.MITRE.ORG!barrattShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!DASH.MITRE.ORG!barratt
From: barratt@DASH.MITRE.ORG (Jeff Barratt)
Newsgroups: gnu.bash.bug
Subject: More :${abc?abc} exits
Message-ID: <9001052019.AA01516@dash.mitre.org>
Date: 5 Jan 90 20:19:00 GMT
Sender: daemon@tut.cis.ohio-state.edu
Reply-To: barratt@dash.mitre.org
Distribution: gnu
Organization: GNUs
Lines: 59