Bug 5338 - tcsh && is not short circuiting
Summary: tcsh && is not short circuiting
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: tcsh
Version: 6.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Nalin Dahyabhai
QA Contact:
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 1999-09-23 20:26 UTC by jfoster
Modified: 2008-05-01 15:37 UTC (History)
1 user (show)

(edit)
Clone Of:
(edit)
Last Closed: 2002-03-25 05:38:22 UTC


Attachments (Terms of Use)

Description jfoster 1999-09-23 20:26:07 UTC
Running the following script yields the error "X11:
Undefined variable," whereas it should exit normally.

-----------------------------------------------------
#!/bin/tcsh

unsetenv X11
if ($?X11 && ($X11 == "huh?")) then
   echo "a"
endif
echo "b"
-----------------------------------------------------

Comment 1 Jeff Johnson 2000-01-10 20:48:59 UTC
This bug is still present in tcsh-6.09-1.

Comment 2 Göran Uddeborg 2001-07-17 21:30:25 UTC
This is not a bug, is it?  Variable expansion takes place in one step for a
complete line, before any evaluation of the expression or execution of command. 
As far as I'm aware, it has always been necessary to do

if ($?X11) then
   if ($X11 == "huh?") then
      echo "a"
   endif
endif

to achieve the desired effect.  Both in tcsh and in the original csh.

Comment 3 jfoster 2001-07-17 22:40:06 UTC
OK, it's a feature then.

Comment 4 Ben Liblit 2001-07-18 00:12:15 UTC
The reported behavior is surprising but correct.  Read "Csh Programming
Considered Harmful", section 6 (Expression Evaluation). 
<http://www.perl.com/pub/a/language/versus/csh.html>


Note You need to log in before you can comment on or make changes to this bug.