Xref: utzoo comp.unix.wizards:15392 comp.bugs.4bsd:1252 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!ames!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.wizards,comp.bugs.4bsd Subject: Re: csh variable syntax '${x1[2]}' is broken. Keywords: unix, csh, variable, substitution, bug Message-ID: <16759@mimsy.UUCP> Date: 5 Apr 89 18:13:34 GMT References: <1893@trantor.harris-atd.com> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 54 Date: Wed, 13 Jan 88 20:36:53 EST From: Chris Torek To: 4bsd-bugs@ucbvax.Berkeley.EDU Subject: csh mislexes $var1iables Index: bin/csh/sh.lex.c 4.3BSD Fix Reference: 4.3BSD/bin/114 Description: The C shell's `lexical analyser' (if you can call it that) thinks that variables are either all digits or all numbers. As far as it is concerned, $a1bc is the variable $a followed by the string `1bc'. Everyone is happy: the lexer sees a properly-formed variable ($a) plus a string, and later, the variable evaluator looks up $a1bc. If, however, one writes instead ${a1bc}, the lexer is not happy. It sees a variable (${a) that is not proper: the closing brace `}' is missing. It complains about variable syntax (an ambiguous error, but here the real meaning is not the intended one!), and the evaluator never gets a chance. Repeat-by: % set a1=ok % echo ${a1} Variable syntax. % man csh (read section on shell variable syntax) Fix: It seems to work. The code is all twisty and devious, so maybe it will break something. I doubt it. Chris *** sh.lex.c.old Wed Jan 13 20:22:06 1988 --- sh.lex.c Wed Jan 13 20:22:10 1988 *************** *** 373,377 **** } } else if (letter(c)) ! while (letter(c = getC(DOEXCL))) { if (np < &name[sizeof name / 2]) *np++ = c; --- 373,377 ---- } } else if (letter(c)) ! while (letter(c = getC(DOEXCL)) || digit(c)) { if (np < &name[sizeof name / 2]) *np++ = c; -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris