brad@SSD.CSD.HARRIS.COM (Brad Appleton) (03/22/90)
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@ssd.csd.harris.com | Computer Systems Division | | ... {uunet | novavax}!hcx1!brad | Fort Lauderdale, FL USA | +-=-=-=-=-=- DISCLAIMER: I said it, not my company! -=-=-=-=-=-=-=-=-+
peter@ficc.uu.net (Peter da Silva) (03/23/90)
> Does anybody know what seems to be the problem? The problem is that csh doesn't actually parse its control structures, it just works on a command-by-command basis and does simple string searches for keywords. > (Perhaps it serves me right > for using csh when I have ksh :-) For shell scripts, either ksh or sh is better than csh. For interactive use, either ksh or csh is better than sh. Use the right tool for the job. -- _--_|\ `-_-' Peter da Silva. +1 713 274 5180. <peter@ficc.uu.net>. / \ 'U` \_.--._/ v
luis@mavrick.UUCP (luis basto) (03/25/90)
In article <NKF2T51xds13@ficc.uu.net>, peter@ficc.uu.net (Peter da Silva) writes: > For shell scripts, either ksh or sh is better than csh. For interactive > use, either ksh or csh is better than sh. Use the right tool for the job. > -- Taking the union of these two statements means use the ksh for all situations. I tend to agree but unfortunately ksh does not exist on all systems. Is it available on Suns? -- Luis Basto Work: (512) 823-2896 Computer Sciences Corp. Usenet: ...!cs.utexas.edu!mavrick!luis Austin, Texas