Re: tcsh bug



On Thu, 28 Sep 2006 06:31:20 -0700, blue wrote:

#! /bin/tcsh -f
# tcsh 6.12.00

if (-e Hce.res) then
fgrep PASSED Hce.res >& /dev/null
if ($status)then
# If you put a space between "($status)" and "then" things work fine.
echo "Hce.res exists:: FAIL1: HCE "
else
echo "Hce.res exists:: PASS2: HCE Test"
endif
else
echo "Hce.res does NOT exist:: FAIL3: "
endif

The problem as you note is your second "if" statement, the lack of a space
following the ")" means that it is not recognized as an "if" by the tcsh
pattern recognizer. Hence the first "else" is paired with the first "if",
and you get the output from the second "echo" if the file does not exist.

So the bug is the lack of warnings from the second "else" and the second
"endif".

More proof, if any was needed, that parsing your input, as "sh" and "rc"
family shells do, is superior to ad-hoc pattern matching. Hence the
usual advice to not use csh (or tcsh) for scripts.
.



Relevant Pages