[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] ash: add process substitution in bash-compatibility mode
From:       Ron Yorston <rmy () pobox ! com>
Date:       2019-01-30 11:10:16
Message-ID: 5c518618.TZ//mikYpFwk0GjX%rmy () pobox ! com
[Download RAW message or body]

Denys wrote:
>On Mon, Jan 28, 2019 at 10:16 AM Ron Yorston <rmy@pobox.com> wrote:
>> Denys wrote:
>> >Can we use popredir() mechanism instead?
>>
>> It's possible but it adds more complication to already complex code.
>> Currently the stack of redir fds is always unwound unconditionally.
>> The procsub fds are conditionally removed depending on whether or not
>> we're in a shell function.
>
>That what looked unusual to me at once. Redirections should not depend
>on things like that.

Redirections shouldn't, but process substitutions aren't the same
as redirections.  My patch copies what bash does:  bash maintains a
separate record of process substitution file descriptors and treats
then differently depending on whether or not we're in a shell function.

Why does it do this?  The Bash Hackers Wiki [1] says this about the
scope of process substitutions:

   If a process substitution is expanded as an argument to a function,
   expanded to an environment variable during calling of a function, or
   expanded to any assignment within a function, the process substitution
   will be "held open" for use by any command within the function or
   its callees, until the function in which it was set returns.

The first two cases aren't problematic and are similar to redirections.
The third case is different.  Outside a function this doesn't work:

   $ SUB=<(echo hi)
   $ cat $SUB
   cat: /dev/fd/63: No such file or directory

Inside a function it does:

   $ f() {
   > SUB=<(echo hi)
   > cat $SUB
   > }
   $ f
   hi

Except...

The examples above were run on bash 4.1.2 in CentOS 6.  The same results
are obtained with bash up to version 4.2.45 (from 2013).  In bash 4.3
and later the third case described in the Wiki no longer works and the
second example also returns:

   cat: /dev/fd/63: No such file or directory

Other shells that support process substitution do the same.

It appears that the special treatment of process substitutions in
shell functions is both obsolete and a bashism.

I'll reconsider my patch in light of this.

Ron

[1] https://wiki-dev.bash-hackers.org/syntax/expansion/proc_subst
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic