[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
moving fd affect outer scope
From: |
Stephane Chazelas |
Subject: |
moving fd affect outer scope |
Date: |
Mon, 18 Feb 2013 19:55:39 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib
-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
-Werror=format-security -Wall
uname output: Linux sc 3.7-trunk-amd64 #1 SMP Debian 3.7.3-1~experimental.1
x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.2
Patch Level: 37
Release Status: release
Moving a file descriptor for a builtin command or a compound
command leaves the fd closed afterwards:
$ bash -c ': <&1-; echo test'
bash: line 0: echo: write error: Bad file descriptor
expected output: "test".
ksh93 had a similar bug but it was fixed in 1994:
94-06-30 A bug which caused 2<&1- when applied to a shell built-in
to leave standard input closed has been fixed.
(don't know if it's a typo above (s/input/output/), if not it
might be a different bug)
In any case, ksh93u+ doesn't exhibit the same behavior as bash:
$ ksh -c ': <&1-; echo test'
test
The longer (standard) form works OK:
$ bash -c ': <&1 1<&-; echo test'
test
--
Stephane
- moving fd affect outer scope,
Stephane Chazelas <=