More C-shell weirdness [Another word count problem]

Chris Torek chris at umcp-cs.UUCP
Fri Apr 4 12:34:19 AEST 1986


In article <684 at nbires.UUCP> nose at nbires.UUCP writes:
>set a = ''
>set a = ($a '')
>echo $#a
>
>Yields 1
>
>set a = ('' '')
>echo $#a
>
>Yields 2

It is all a matter of quoting:

	set a = ''; set a = ("$a" ''); echo $#a

gives `2'.  Your first example gives `1' because the C shell
does history substitution (none), then variable expansion---now
the command is

	set a = ( '')

---then alias expansion (none), and finally executes it.  With
the double quotes, variable expansion yeilds

	set a = ("" '')

which is of course two words.

It is often important to quote variables being expanded.  For
instance:

	set a = '*'
	set a = ($a)
	echo $a

prints the same thing as `echo *'.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix.wizards mailing list