Re: ${ ...; } can end up closing user fds open within
From:
Chet Ramey
Subject:
Re: ${ ...; } can end up closing user fds open within
Date:
Fri, 23 Jan 2026 10:16:26 -0500
User-agent:
Mozilla Thunderbird
On 1/23/26 4:37 AM, Stephane Chazelas wrote:
Bash Version: 5.3
Patch Level: 3
Release Status: release
(same in current "devel" git head (commit
c4b56ed9ac00424bde0f9ce3adfb7edb3d19a557)
Description:
$ bash -c 'echo "${ exec 4> /dev/null && echo OK; }"; ls -dog "/proc/$$/fd/4"'
OK
l-wx------ 1 64 Jan 23 09:22 /proc/19083/fd/4 -> /dev/null
fine, but when 4 is the first free fd like after:
$ exec 3>&1
$ bash -c 'echo "${ exec 4> /dev/null && echo OK; }"; ls -dog "/proc/$$/fd/4"'
ls: cannot access '/proc/19106/fd/4': No such file or directory
Thanks for the report. It's an easy fix.
--
``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/