More C-shell weirdness [Another word count problem]

Karl Kleinpaste karl at cbrma.UUCP
Fri Apr 4 02:30:33 AEST 1986


In article <684 at nbires.UUCP> nose at nbires.UUCP (Steve Dunn) writes:
>This:
>set a = ''
>set a = ($a '')
>echo $#a
>Yields 1
>
>But this:
>
>set a = ('' '')
>echo $#a
>Yields 2
>
>This curious behavior has not actually caused me any trouble but I
>am a bit puzzled

It's because of the order in which things are being substituted in the
input line.  That is, what is happening is that
	set a = ($a '')
becomes
	set a = ( '')
when $a's empty value is stuffed into the line.  Then the
interpretation of the remainder gives `a' the single value ''.

As a counterpoint, try
	set a = ''
	set a = ("$a" '')
	echo $#a
which yields 2.  The reason is that you've stipulated extra quotings,
which preserve values for longer than the simple replacement of $a in
the input line with its null value.  The use of double quotes causes
$a to be interpreted within them, subsituting its null string, while
leaving that null string quoted, so that two null strings result.
-- 
Karl Kleinpaste



More information about the Comp.unix.wizards mailing list