home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!decwrl!csus.edu!netcom.com!darrell
- From: darrell@netcom.com (Darrell Sell)
- Subject: C shell nested 'if' problem
- Message-ID: <=+dn+c-.darrell@netcom.com>
- Date: Fri, 28 Aug 92 03:39:45 GMT
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- Followup-To: comp.unix.shell
- Distribution: usa
- Keywords: csh
- Lines: 39
-
- I have a csh problem with nested if--else if--else statements. The
- example below, gives the expected branching behavior, only if the parens
- are removed from the first inner if expression. With the parens
- it gets confused if the first if expression is false.
-
- Does anyone have an explanation? This is not just an exercise to try to
- stump the experts, I have a client with a few thousand lines of csh scripts
- that I am modifying. I can probably get around the problem by changing
- one of the if chains into a switch, but I would like to understand what
- is going on.
-
- Books like "Unix in a Nutshell" or "The Unix C Shell Field Guide" or the
- csh man page don't say anything on the topic.
-
- Thanks. You can respond to this news group or send replies directly to me
- at darrell@netcom.com.
-
- =============test script
- #! /bin/csh -f
- #
- if( $1 == 1) then
- echo "first if is true, param = $1"
- if $2 == "a" then
- echo "inner if true, alpha = $2"
- else if($2 == "b") then
- echo "first inner else if true, alpha = $2"
- else
- echo "inner else loop, alpah = $2"
- endif
- else if ($1 == 2) then
- echo "first outer else if is true, param = $1"
- else if( $1 == 3) then
- echo "second outer else if is true, param = $1"
- else
- echo "outer else, param = $1"
- endif
- exit 0
-
-
-