Re: [PATCH] filter-branch: Avoid an error message in the map function.
- From
Johannes Sixt <j.sixt@eudaptics.com>
- Date
- Jul 4, 2007, 11:45 UTC
- Message-ID
- <468B8852.CB36968@eudaptics.com>
- In-Reply-To
- <Pine.LNX.4.64.0707041205250.4071@racer.site>
Johannes Schindelin wrote:
Show 21 quoted lines
> > Hi, > > On Wed, 4 Jul 2007, Johannes Sixt wrote: > > > - test -r "$workdir/../map/$1" || echo "$1" > > - cat "$workdir/../map/$1" > > + test -r "$workdir/../map/$1" && > > + cat "$workdir/../map/$1" || > > + echo "$1" > > I think this does not do what you want. If I read it correctly, it will > not do anything if $workdir/../map/$1 is not readable. I think you need > this: > > (test -r "$workdir/../map/$1" && > cat "$workdir/../map/$1") || > echo "$1" > > But that is a little too cute, so I personally would prefer an > if-then-else-fi, because that is the idea of that code snippet.
It does do what I think it should do. I tested it. Your elaborate version is not required. The reason is that in the shell && and || have equal precedence; if there is ... && cmd ... then cmd is run if the most recent result is success, and if there is ... || cmd ... then cmd is run if the most recent result is failure; in both cases cmd is otherwise skipped and does not count as "most recent result".
-- Hannes