Re: using exec to close a fd in a var crashes bash
From:
Grisha Levit
Subject:
Re: using exec to close a fd in a var crashes bash
Date:
Sun, 20 Aug 2023 00:15:33 -0400
On Sat, Aug 19, 2023, 16:42 jleivent <jleivent@comcast.net> wrote:
> bash: exec: 10: not found
> But even that shouldn't cause the shell to terminate if the
> target isn't found, so maybe this is two bugs?
>
> Repeat-By:
>
> 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.
>