[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
using exec to close a fd in a var crashes bash
From: |
jleivent |
Subject: |
using exec to close a fd in a var crashes bash |
Date: |
Sat, 19 Aug 2023 13:37:31 -0400 |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat
-Werror=format-sec> uname output: Linux lapdog 6.1.0-11-amd64 #1 SMP
PREEMPT_DYNAMIC Debian 6.1.38-> Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.2
Patch Level: 15
Release Status: release
Description:
Using exec to close a file descriptor in a variable crashes
bash. It doesn't matter how the fd got into the variable, but
the likely usage is with the {varname} form, as illustrated
below. I think what is happening is that the exec arg is being
parsed as a target to execute instead of a fd redirection,
because when executed in two levels of shell (to allow the
inner one to crash while leaving the outer), it generates the
following error message:
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?
Also note that the quoting and {} around foo in the last line
don't impact the bug.
This bug makes it difficult to use {varname} forms for file
descriptors, as it means there is no easy way to close them
before script exit.
Repeat-By:
exec {foo}>/tmp/foo
exec "${foo}"<&-
- using exec to close a fd in a var crashes bash,
jleivent <=