Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: pipelines and &&
- X-seq: zsh-users 1546
- From: John Riddoch <jr@xxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxxx
- Subject: Re: pipelines and &&
- Date: Mon, 25 May 1998 11:46:04 +0100 (BST)
- Reply-to: John Riddoch <jr@xxxxxxxxxxxxxx>
> 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@xxxxxxxxxxxxxx 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author