zsh-workers
 help / color / mirror / code / Atom feed
* this && that || the other && this too
@ 1997-10-08  0:47 ramos
  1997-10-08  3:17 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: ramos @ 1997-10-08  0:47 UTC (permalink / raw)
  To: zsh-workers


hello zsh developers! Congrats on a very nice job.

I found a "problem" that perhaps some interested volunteer
would care to look into.
Consider it a special exercise for those who thought zsh
already implements all shell features that can possibly be
implemented :-)

Apparently there is no way to construct an expression
using "&&" and "||" of the form:

	cmd1 XX cmd2 XX cmd3

such that both cmd2 and cmd3 execute when cmd1 succeeds,
and neither cmd2 nor cmd3 execute when cmd1 fails.

examples that do not work:

% echo yo && true || echo A || echo B     
yo

% echo yo && false || echo A || echo B 
yo
A

% echo yo && true || echo A && echo B 
yo
B
 
% echo yo && false || echo A && echo B 
yo
A
B

"It would be nice" to be able to do this without using ()'s, or
if/then/fi, or some other contorted workaround.

Thanks,

Alex Ramos
atramos@lucent.com

% echo $ZSH_VERSION
3.0.5

% uname -a
SunOS ihnns581 5.5.1 Generic_103640-09 sun4u sparc SUNW,Ultra-1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: this && that || the other && this too
  1997-10-08  0:47 this && that || the other && this too ramos
@ 1997-10-08  3:17 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1997-10-08  3:17 UTC (permalink / raw)
  To: ramos, zsh-workers

On Oct 7,  7:47pm, ramos@ih4ess.ih.lucent.com wrote:
} Subject: this && that || the other && this too
}
} Apparently there is no way to construct an expression
} using "&&" and "||" of the form:
} 
} 	cmd1 XX cmd2 XX cmd3
} 
} such that both cmd2 and cmd3 execute when cmd1 succeeds,
} and neither cmd2 nor cmd3 execute when cmd1 fails.

Yes, that's correct.  `&&' and `||' behave mostly like the boolean
operators in C, so they execute exactly as many subexpressions, left to
right, as are needed to determine the success or failure status of the
entire expression.  They differ from C in having equal precedence, so
they evaluate strictly left to right unless grouped with ( ) or { }.

This is distinct from `;' and `&' which execute both the left and right
subexpressions regardless of the exit status of the left one.

} "It would be nice" to be able to do this without using ()'s, or
} if/then/fi, or some other contorted workaround.

It would be confusing, is what it would be.

What you want, it sounds like, is

	cmd1 && { cmd2 ; cmd3 }

The only way to get that without the { } would be to introduce a new
command separator that acted like `;' but that had higher precedence
than `&&'.  That behavior would be unlike any other separator in zsh
or any other shell.

There's nothing "contorted" about the { } form.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-10-08  3:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-08  0:47 this && that || the other && this too ramos
1997-10-08  3:17 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).