csh variable syntax '${x1[2]}' is broken.

Chris Torek chris at mimsy.UUCP
Thu Apr 6 04:13:34 AEST 1989


Date: Wed, 13 Jan 88 20:36:53 EST
From: Chris Torek <chris at gyre.umd.edu>
To: 4bsd-bugs at 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 at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list