simon@its63b.ed.ac.uk (ECSC68 S Brown CS) (12/07/86)
In article <106@quacky.UUCP> dce@quacky.UUCP (David Elliott) writes: > >There is one slight problem with "$@", which can be shown by the following > > [... example of the wll-known "feature" ...] > >Anyway, the following statement can be used to fix this bug in most >versions of sh. > > if (strcmp (as, "\"$@\"") == 0 && dolc == 0) { > return(fixstak()); > } > >Add these to the beginning of the subroutine macro() in macro.c, and the >bug goes away. It is somewhat kludgy, but it works. > However, if you fix this in your version of sh, it makes any shell-scripts that you may write assuming the "fixed" behaviour inherently non-portable, 'cos they'll immediately bomb out on standard shells. So, until the fix described above (or some equivalent thereof) is official, its probably better just to be very careful when using $* or $@ in scripts. One foolproof way is to always use ${1+"$@"} in place of $* or $@ or "$@" - ok, its ugly, I know... :-) -- Simon Brown Department of Computer Science, University of Edinburgh, Scotland. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "Life's distressing - that's no blessing". [Anon.] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bde@ihlpl.UUCP (12/10/86)
In article <164@its63b.ed.ac.uk>, simon@its63b.ed.ac.uk (Simon Brown) says: > : > > So, until the fix described above (or some equivalent thereof) is official, > its probably better just to be very careful when using $* or $@ in scripts. > One foolproof way is to always use ${1+"$@"} in place of $* or $@ or "$@" > - ok, its ugly, I know... :-) > Oh my goodness! It's all a plot! Even in UN*X, we have AT&T encouraging "1 plus" dialing of operators! -- disclaimer: my company doesn't know I exist, let alone that I posted this. "opinions generated by beating the keyboard with a baseball bat" -- Bryan Ewbank, ...!ihnp4!ihlpl!bde ih 6M-523 / AT&T Bell Labs / Naperville, IL 60566 / USA -- -- "opinions generated by beating the keyboard with a baseball bat" -- Bryan Ewbank, 312/979-4296, ...!ihnp4!ihlpl!bde, ih 6M-523 / AT&T Bell Labs / Naperville, IL 60566 / USA
karl@haddock.UUCP (12/13/86)
In article <164@its63b.ed.ac.uk> simon@its63b.ed.ac.uk (ECSC68 S Brown CS) writes: >In article <106@quacky.UUCP> dce@quacky.UUCP (David Elliott) writes: >>Anyway, the following statement can be used to fix [the $@ bug] ... > >However, if you fix this in your version of sh, it makes any shell-scripts >that you may write assuming the "fixed" behaviour inherently non-portable, >'cos they'll immediately bomb out on standard shells. Shell scripts are already non-portable across versions of UNIX. The three major branches (Research, USG, and Berkeley) have distinct versions of echo! Hopefully the $@ fix will be applied to an entire branch rather than being done individually at each installation. (I presume nobody *depends* on this bug...) Research V8 has already applied the fix, I believe. >So, until [it] is official, its probably better just to be very careful... >One foolproof way is to always use ${1+"$@"} in place of $* or $@ or "$@"... Hey! That's not bad! I've been using crap like if [ $# = 0 ]; then cmd; else cmd "$@"; fi which is uglier -- if your notation really works (it should, but I'm going to run some tests before I rewrite things) I'll convert my shell scripts. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint Btw, the V8 echo is the best of the lot; I hope the others adopt it.
ado@elsie.UUCP (Arthur David Olson) (12/16/86)
The problem: you set up a one-line "sh" script named "feline" that reads c "$@" hoping that you can then use the command "c" rather than "cat". But things go awry if you grep uucp /etc/passwd | c Another poster's earlier posting: a fix to "sh" to handle "$@" the way it "ought" to be handled, with a wise caution that scripts relying on the fixed sh's handling of "$@" won't be portable. My notion: instead of changing the behavior of "$@", introduce a new '$' sequence that does what "$@" ought to do--for example, set things up so that cat "${" does what ought to be done by cat "$@" The advantage of doing this: if a cat "${" script is run on an "old" shell, you'll get a bad substition error rather than getting the incorrect results. The "old" shell will have recognized that you've asked it to do something it doesn't know how to do. -- UUCP: ..decvax!seismo!elsie!ado ARPA: elsie!ado@seismo.ARPA DEC, VAX, Elsie & Ado are Digital, Borden & Ampex trademarks.