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: Ángel
Subject: Re: using exec to close a fd in a var crashes bash
Date: Thu, 24 Aug 2023 04:21:51 +0200

On 2023-08-23 at 10:34 -0400, Greg Wooledge wrote:
> So... {var}> redirections were introduced in bash 4.1, and
> varredir_close in bash 5.2.  That means that in all versions from
> bash 4.1 to 5.1, you will need the separate "exec {fd}>&-" to close
> the temp FD.  At this point, it hardly seems worthwhile to make use
> of a feature that only works in bash 5.2, which is surely a tiny
> fraction of the set of installed bash instances in the world.
> 
> Perhaps in a decade or so, when bash 5.2+ instances are the majority,
> it will make sense to expect that feature to exist.  But you'd still
> need fallback code for the rest.
> 
> Then again... leaving an FD open in a shell script usually won't
> matter, because the script will exit, and that'll just take care of
> it.  The only times it actually matters are long-running bash
> processes --either interactive shells, or some kind of weird daemon
> that's been implemented in bash for some reason -- or scripts that
> open and (fail to) close lots of temp FDs in a loop.
> 
> So, unless you're using this feature in an interactive shell function
> or programmable completion or something, I guess it can mostly be
> ignored.

You can just toss out
shopt -s varredir_close 2> /dev/null || true  # Close varredir_close on bash 
5.2+

at the top of the script, and have correct behavior with recent bash, and
small-fd-leak-but-otherwise-working on previous versions that are 4.1+.







reply via email to

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