zsh-users
 help / color / mirror / code / Atom feed
* Re: pipelines and &&
@ 1998-05-25 10:46 John Riddoch
  0 siblings, 0 replies; 6+ messages in thread
From: John Riddoch @ 1998-05-25 10:46 UTC (permalink / raw)
  To: zsh-users

> I would very much like to know how sublists and pipelines are done:
> I read the following without understanding how to do it:
> 
> "If two pipelines are separated by ``&&'', the second
> pipeline is executed only if the first is successful (returns a zero
> value).  If two pipelines are separated by ``||'', the second is
> executed only if the first is unsuccessful (returns a nonzero value).
> Both operators have equal precedence and are left associative."

This has nothing to do with pipes; the term is probably somewhat confusing.

A better example would be:

cp file file.bak || echo "file not backed up"

If the file could not be backed up (eg, the file does not exist or the user 
does not have write permission in the directory), then the error message is 
shown.  Alternatively:

cp file file.bak && echo "file backed up"

|| and && are alternatives to testing $?
eg:

cp file file.bak
if [ $? = 0 ]; then echo "file backed up"; done

is equivalent to the second example above.  However, || and && are shorter and 
can be slightly more understandable.

--
John Riddoch	Email: jr@scms.rgu.ac.uk	Telephone: (01224)262721
Room C6, School of Computer and Mathematical Science
Robert Gordon University, Aberdeen, AB25 1HG
And yeah, as I walk through the valley of the shadow of Death, I shall
fear no evil, 'cause I'm packing an M60 with explosive ammo.


^ permalink raw reply	[flat|nested] 6+ messages in thread
* pipelines and &&
@ 1998-05-25  9:46 Matthias Kopfermann
  1998-05-25 10:36 ` Thomas Koehler
  1998-05-25 16:38 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Matthias Kopfermann @ 1998-05-25  9:46 UTC (permalink / raw)
  To: zsh-users

I would very much like to know how sublists and pipelines are done:
I read the following without understanding how to do it:

"If two pipelines are separated by ``&&'', the second
pipeline is executed only if the first is successful (returns a zero
value).  If two pipelines are separated by ``||'', the second is
executed only if the first is unsuccessful (returns a nonzero value).
Both operators have equal precedence and are left associative."

now i try something like:
	ls | wc && | less  (just to understand the mechanism)
      
		^       ^
	There are two pipelines 1) | wc
									2) | less
	They are separated by &&.
		Result: "zsh: parse error near `|'"

I seem to do it wrong.
could you give some examples here?


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

end of thread, other threads:[~1998-05-26 19:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-25 10:46 pipelines and && John Riddoch
  -- strict thread matches above, loose matches on Subject: below --
1998-05-25  9:46 Matthias Kopfermann
1998-05-25 10:36 ` Thomas Koehler
1998-05-26 18:01   ` Matthias Kopfermann
1998-05-26 19:38     ` Bart Schaefer
1998-05-25 16:38 ` 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).