Possible big in C-Shell

Brad Appleton brad at SSD.CSD.HARRIS.COM
Fri Mar 23 01:01:10 AEST 1990


I apologize if this was brought up before; I have not seen it here...

I am having a problem in the C-Shell. I have a here document inside 
an if statement, and the here document contains the word "else". When
the "if" condition is false, it seems that the "else" part of the 
here document is executed.

I have isolated the problem into a simple script:

     foreach i (foo bar)
       echo "i=$i"

       if ( $i == foo ) then
         cat >tmp <<END_HERE_DOC
                  =====start of here document=====
                  else echo "this is from the here document"    
                  ======end of here document======
     END_HERE_DOC
         echo "done with here document"

       else
         echo "this is not from the here document"
       endif

     end

This script produces the following output:

     i=foo
     done with here document
     i=bar
     this is from the here document
     ======end: Command not found.
     END_HERE_DOC: Command not found.
     done with here document

If I use the following Bourne/Korn script:


     for i in foo bar; do
       echo "i=$i"

       if [ $i = foo ] ; then
         cat >tmp <<END_HERE_DOC
                  =====start of here document=====
                  else echo "this is from the here document"    
                  ======end of here document======
     END_HERE_DOC
         echo "done with here document"

       else
         echo "this is not from the here document"
       fi

     done

I get the following output (for sh and ksh):

     i=foo
     done with here document
     i=bar
     this is not from the here document

Does anybody know what seems to be the problem? Is this in fact a bug or
Am I doing something wrong that I cant see? (Perhaps it serves me right 
for using csh when I have ksh :-)

advTHANXance

+-=-=-=-=-=-= "... and miles to go before I sleep." -=-=-=-=-=-=-=-=-+
|  Brad Appleton                       |  Harris Corporation         |
|      brad at ssd.csd.harris.com         |  Computer Systems Division  |
|     ... {uunet | novavax}!hcx1!brad  |  Fort Lauderdale, FL  USA   |
+-=-=-=-=-=- DISCLAIMER: I said it, not my company! -=-=-=-=-=-=-=-=-+



More information about the Comp.unix.wizards mailing list