[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: command substitution is stripping set -e from options
From: |
Christoph Gysin |
Subject: |
Re: command substitution is stripping set -e from options |
Date: |
Thu, 8 Oct 2015 21:36:59 +0300 |
> I think you're overlooking what I referred to above: that the exit status
> of a command substitution doesn't have any effect on whether the parent's
> command succeeds or fails except in one case: the right-hand-side of an
> assignment statement that is the last assignment in a command consisting
> only of assignment statements. To say that it `disables the whole point
> of set -e' is a considerable overstatement.
Well, I do see your point. But my understanding was that if I wanted
to run all my bash code with set -e error checking, I can do so by
avoiding a couple of corner cases, namely:
Instead of:
local var=$(cmd)
I use:
local var
var=$(cmd)
and instead of:
command $(cmd)
I use:
var=$(cmd)
command $var
etc.
But this issue brings a new corner case:
func() {
cmd1
cmd2
}
var=$(func)
This won't work, because set -e is stripped inside the substitution,
so the whole function runs without error checking.
So while set -e has it's issues, it is still very useful to have all
commands error checked if one is aware of the corner cases. Well, all
except the one I described, which seems impossible to work around.
The only workaround I can think of is to put set -e in the beginning
of every function. That would make it possible to catch errors in the
example above. But it is really ugly. I would like to set -e once in
the beginning of the script, and not all over in every function.
Is there another way to achieve this?
Is it out of the question to change this behaviour?
If so, would you accept a patch that adds an option to enable that behaviour?
Thanks,
Chris
--
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org@fr33z3
- Re: command substitution is stripping set -e from options, (continued)
- Re: command substitution is stripping set -e from options, Eric Blake, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/09
- Re: command substitution is stripping set -e from options,
Christoph Gysin <=
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/10
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/13
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/15
- Re: command substitution is stripping set -e from options, Linda Walsh, 2015/10/15