bug-bash
[Top][All Lists]
Advanced

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

Re: using exec to close a fd in a var crashes bash


From: Chet Ramey
Subject: Re: using exec to close a fd in a var crashes bash
Date: Mon, 21 Aug 2023 16:00:55 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0

On 8/20/23 12:15 AM, Grisha Levit wrote:

         exec {foo}>/tmp/foo
         exec "${foo}"<&-


Looks like bash doesn't undo redirections if the exec fails -- so the shell
terminates because the redirection closed stdin.

I agree it would probably make sense to undo them if the exec fails and the
shell is not going to exit.

The latest draft of the upcoming POSIX revision says:

"If the exec command fails and the shell does not exit, any redirections
associated with the exec command that were successfully made shall take
effect in the current shell execution environment."

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

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