Bug 5338

Summary: tcsh && is not short circuiting
Product: [Retired] Red Hat Linux Reporter: jfoster
Component: tcshAssignee: Nalin Dahyabhai <nalin>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6.0CC: goeran
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-03-25 05:38:22 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

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


unsetenv X11
if ($?X11 && ($X11 == "huh?")) then
   echo "a"
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"

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).