[Tcsh] here-document in if-then-else-endif

Michal Szymanski msz at astrouw.edu.pl
Fri Mar 20 12:07:06 UTC 2020


Hi

I have encountered strange behavior in here-docs placed inside "if"
command. Consider:

#!/bin/tcsh -f
set M=0
if ( $M ) then
cat <<EOF >! /tmp/here.out
if (x>0)
  y=1;
else
  y=2;
EOF
else
cat <<EOF >! /tmp/here.out
if (x<0)
  y=1;
else
  y=2;
EOF
endif

Executing the above script results in:

y=2: Command not found.
EOF: Command not found.

Seems that if $M is 0, tcsh does not recognize "cat << EOM" construct
in the "if" part of the conditional and treats the "else" line inside
the here-doc as a part of the script syntax.

Is that an expected behavior?

regards, Michal

PS. I have not noticed that TCSH mailing list moved to a new address
(from mx.gw.com) until today. Apparently the old list subscribers were
not transferred automatically.

-- 
  Michal Szymanski (msz at astrouw dot edu dot pl)
  Warsaw University Observatory, Warszawa, POLAND


More information about the Tcsh mailing list