bug-bash
[Top][All Lists]
Advanced

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

Re: in-line calls to functions cause "exit" in the function to act like


From: Kerin Millar
Subject: Re: in-line calls to functions cause "exit" in the function to act like "return"
Date: Sat, 18 Dec 2021 16:03:14 +0000

On Sat, 18 Dec 2021 13:07:03 +0000
yesxorno via Bug reports for the GNU Bourne Again SHell <bug-bash@gnu.org> 
wrote:

> Description:
> 
> When 'exit' is executed in a function called to "in-line" its output to 
> stdout, the 'exit' acts like return, leaving the function scope, but not 
> terminating the bash process.

It does, in fact, exit the subshell in question.

> 
> Repeat-By:
> 
> Sample script:
> 
> #!/bin/bash
> 
> set -x
> 
> function bar()
> {
>     exit 1
> }
> 
> foo="$(bar)"

Here, the use of a command substitution causes a subshell to be created. The 
command, exit 1, is not run by the shell that the kernel loaded to interpret 
your script.

-- 
Kerin Millar



reply via email to

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