bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ordering bug when handling redirection with file descriptors


From: Érico Nogueira
Subject: Ordering bug when handling redirection with file descriptors
Date: Sun, 31 Jan 2021 17:40:48 -0300

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

With dash, it will simply exit silently (and `b` will be set to "a"), but with current bash it errors out with the following error message:

test: line 10: 4: Bad file descriptor

This test case was taken from a real world example,
https://github.com/skarnet/skalibs/blob/f2c9b3cb899555af1a295df7341afc1cf55f7c71/configure#L322

While exploring similar issues, I found that

fn() {
        echo a >&3
}

echo `fn 3>&1 1>&4 4>&-` 4>&1


also fails, but in this case dash doesn't seem to get it correct either.

I can provide straces for these, if necessary. This is all on Linux.

Thanks,
Érico



reply via email to

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