[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: command substitution is stripping set -e from options
From: |
Greg Wooledge |
Subject: |
Re: command substitution is stripping set -e from options |
Date: |
Thu, 8 Oct 2015 14:49:39 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Oct 08, 2015 at 09:36:59PM +0300, Christoph Gysin wrote:
> 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.
I know you don't want to hear this, but you really need to stop thinking
of set -e as "error checking". It is an obsolescent historical anomaly
that bash is required to support because POSIX specifies it. It isn't
useful for any purpose, and people who insist on using it are simply
causing extra pain for themselves.
Bash does not have automatic error checking. Instead, it uses the C
model: you need to check for erroneous results yourself, after every
command whose results you actually care about.
If you dislike this, then switch your project to a programming language
that *has* automatic error checking. Bash is just a shell, and there
are many other languages that may better suit your project.
- 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, 2015/10/08
- Re: command substitution is stripping set -e from options,
Greg Wooledge <=
- 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