home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / shell / 3675 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.6 KB  |  52 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!decwrl!csus.edu!netcom.com!darrell
  3. From: darrell@netcom.com (Darrell Sell)
  4. Subject: C shell nested 'if' problem
  5. Message-ID: <=+dn+c-.darrell@netcom.com>
  6. Date: Fri, 28 Aug 92 03:39:45 GMT
  7. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  8. Followup-To: comp.unix.shell
  9. Distribution: usa
  10. Keywords: csh
  11. Lines: 39
  12.  
  13. I have a csh problem with nested if--else if--else statements.  The 
  14. example below, gives the expected branching behavior, only if the parens
  15. are removed from the first inner if expression.  With the parens
  16. it gets confused if the first if expression is false.
  17.  
  18. Does anyone have an explanation?  This is not just an exercise to try to
  19. stump the experts, I have a client with a few thousand lines of csh scripts
  20. that I am modifying.  I can probably get around the problem by changing 
  21. one of the if chains into a switch, but I would like to understand what
  22. is going on.
  23.  
  24. Books like "Unix in a Nutshell" or "The Unix C Shell Field Guide" or the
  25. csh man page don't say anything on the topic.
  26.  
  27. Thanks. You can respond to this news group or send replies directly to me
  28. at darrell@netcom.com.
  29.  
  30. =============test script
  31. #! /bin/csh -f
  32. #
  33. if( $1 == 1) then
  34.     echo "first if is true, param = $1"
  35.     if  $2 == "a"   then
  36.         echo "inner if true, alpha = $2" 
  37.       else if($2 == "b") then 
  38.           echo "first inner else if true, alpha = $2"
  39.       else  
  40.         echo "inner else loop, alpah = $2"
  41.       endif
  42.  else if ($1 == 2) then
  43.      echo "first outer else if is true, param = $1"
  44.  else if( $1 == 3) then
  45.      echo "second outer else if is true, param = $1"
  46.  else
  47.      echo "outer else, param = $1"
  48. endif
  49. exit 0
  50.     
  51.  
  52.