Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: &&||



On Mon, 19 Feb 2018 14:47:12 -0800
Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> > You can affect the precedence with braces, but they need to surround the
> > "&&" or "||" expression you want to protect.  In your case you've simply
> > surrounded a pipeline which would be run in one go anyway:
> That's my question, could my code be made to work more or less as it 
> is?

I think you were trying to make the status depend only on what was
before the first "&&".  You can certainly do

first-statement && {
   any-old-stuff
}

and it does have the effect of "if", though there's no obvious reason to
prefer this form (some old shell code is indeed written this way).  The
key points are

- the open brace is the first thing after the &&
- the close brace is after the last thing you want controlled by the
status of first-statement.

The real point, perhaps, is to be able to separate out that
any-old-stuff as something contained within the block, however
complicated it is by itself, so you may just have been getting
distracted by pipelines and ||s etc.

pws



Messages sorted by: Reverse Date, Date, Thread, Author