bug-bash
[Top][All Lists]
Advanced

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

Re: Ordering bug when handling redirection with file descriptors


From: Oğuz
Subject: Re: Ordering bug when handling redirection with file descriptors
Date: Mon, 1 Feb 2021 08:04:18 +0300

31 Ocak 2021 Pazar tarihinde Érico Nogueira <ericonr@disroot.org> yazdı:
>
> #!/bin/sh
>
> fn() {
>         echo a >&3
> }
>
> b=`fn 3>&1 1>&4 4>&-` 4>&1


Not a bug, POSIX allows implementations to perform assignments before
redirections in this case. To guarantee `4>&1' is in effect while `b=`fn
3>&1 1>&4 4>&-`' is being expanded, you should do:

    { b=`fn 3>&1 1>&4 4>&-`; } 4>&1


> While exploring similar issues, I found that
>
> fn() {
>         echo a >&3
> }
>
> echo `fn 3>&1 1>&4 4>&-` 4>&1
>
>
> also fails
>

Command substitutions are expanded before redirections are performed.


-- 
Oğuz


reply via email to

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