bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Command substitution and exiting from deeply nested subshells


From: Greg Wooledge
Subject: Re: Command substitution and exiting from deeply nested subshells
Date: Mon, 7 Oct 2013 08:03:52 -0400
User-agent: Mutt/1.4.2.3i

On Sun, Oct 06, 2013 at 09:37:00PM -0300, Carlos Pita wrote:
>   I'm not completely sure whether this is a bug or not but it seems
> not possible to immediately exit a shell when an error happens at 2+
> levels of subshell nesting.

Exiting in a subshell will never cause the parent shell to exit,
regardless of depth.

imadev:~$ (exit 1); echo I did not exit
I did not exit

If you want a child process (which includes subshells) to be able to
tell the parent process to terminate, then you must arrange some
interprocess communication channel to send that information.  This
could be as simple as "if I return -1, you should exit", or it could
be something more complicated involving signals, or a file, or a named
pipe.

> I've tested this with set -e, set -E, an ERR trap,

All of those are useless and should be avoided.  If handling errors
is important to you, then you should handle them.  Yourself.
See http://mywiki.wooledge.org/BashFAQ/105 for details.

Bash is required to IMPLEMENT set -e because it's in the POSIX
specification.  You are not required to USE it.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]