Yet even MORE Csh Quirks

argv at ucb-vax.ARPA argv at ucb-vax.ARPA
Thu Apr 18 23:09:37 AEST 1985


(Yell at me if you're sick of them)
This is the case of the matching "if" statements with their respective
"endif" statements. It seems that "endif"'s don't know who they are
ending.  Exibit A:

#!/bin/csh -f
@ count = 0
if($#argv == 2) then
    echo hi there
    if( 1 ) then  # this statement if obviously a no-op.
	@ count++  # count should be 1
	echo true
    endif
    echo hi there again
    @ count++      # count should be 2
endif
echo count = $count  

if argv is NOT 2, then $count should be 0, right?!
else count should be 2...  but in ANY event, count
should NEVER be 1. Also, you should either see, 
"hi there" AND "hi there again" or NEITHER, am I right?

The fault lies in the fact that you can't have nested if statements.
The first endif it sees ends ALL ifs, not just the one associated with
it.  If this is the case, why aren't I getting syntax errors for the 
extra (non-matching) endif?

						Dan Heller (aka Frank)
------------------------------------------------------------------------------
		UCSC Computing Center Consultant
      (Looking for a UNIX/C hacking Job - nudge nudge wink wink)

UUCP:    ucbvax!ucscc!argv  {ihnp4,sun,cbosgd,decwrl}!qubix!ucscc!argv
ARPA:    argv%ucscc.uucp at ucb-vax.arpa
CSnet:   c.argv at ucsc.csnet

                   (say no more, say no more)
-------------------------------------------------------------------------------

p.s. csh man entry doesn't address this (at least OURS doesn't).



More information about the Comp.unix.wizards mailing list