[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Ordering bug when handling redirection with file descriptors
From: |
Chet Ramey |
Subject: |
Re: Ordering bug when handling redirection with file descriptors |
Date: |
Mon, 1 Feb 2021 09:49:05 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 |
On 1/31/21 3:40 PM, Érico Nogueira wrote:
Hi! I have the below test case which works with dash, zsh, and has been
reported to work at least up to bash 4.4.12. After 4.4.23 it definitely no
longer works (I have also tested with 5.1.4).
#!/bin/sh
fn() {
echo a >&3
}
b=`fn 3>&1 1>&4 4>&-` 4>&1
I can't find a bash version where this has ever `worked'. The `1>&4' means
to dup fd 4 to fd 1, and at the time this is called, fd 4 is invalid. Bash
always does word expansions and variable assignments before redirections
when executing simple commands, so when the command substitution is called,
the `outer' redirection has not been performed.
While exploring similar issues, I found that
fn() {
echo a >&3
}
echo `fn 3>&1 1>&4 4>&-` 4>&1
Bash is clearly correct here; the command substitution is performed before
the `outer' redirection, and fd 4 is invalid when the shell attempts
`1>&4'.
--
``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/
- Re: Ordering bug when handling redirection with file descriptors,
Chet Ramey <=