More C-shell weirdness [Another word count problem]

jsdy at hadron.UUCP jsdy at hadron.UUCP
Thu Apr 3 16:36:16 AEST 1986


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

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

2

Note that $a, where a is empty or containing all manner of
white space, gets fed back into the parser just as it appears:
as no characters or white space.  To be taken seriously, it
must appear in double quotes (which does sometimes cause
problems).

Consider:
	if ($a == "") ...
	if ("" == "$a") ...
I use the latter form, partly because $a might be -x or something
(!).  The former form could all too easily turn into
	if ( == "")
if what you  r e a l l y  wanted to test was true.  Testing this,
I am enthralled to find that if ( == "") and even if ( == ) both
test out true in csh!!!  I guess this is because of the parsing
that occurs at different times, as I mentioned in another letter.
This gives a syntax error in any sh that I've ever used: Thompson,
Mashey, Bourne, or Korn.
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.unix.wizards mailing list