help-bash
[Top][All Lists]
Advanced

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

Re: Process substitution documentation request


From: Zachary Santer
Subject: Re: Process substitution documentation request
Date: Thu, 25 Jun 2026 18:29:32 -0400

On Thu, Jun 25, 2026 at 7:32 AM Greg Wooledge <greg@wooledge.org> wrote:
>
> sudowrap() {
>     local arg max=3
>     for arg; do
>         if [[ $arg =~ ^/dev/fd/([0-9]+)$ ]]; then
>             max=$(( BASH_REMATCH[1]+1 > max ? BASH_REMATCH[1]+1 : max ))
>         fi
>     done
>     sudo --close-from="$max" "$@"
> }

> hobbit:~$ sudowrap diff <(echo 1) <(echo 2)

Alright, you win. And that's fairly simple to boot.

> I'd go with named pipes, if the goal is "everywhere".

If the system doesn't support /dev/fd/n, the process substitutions are
going to use named pipes. The names of the named pipes wouldn't begin
with "/dev/fd/", so the above code would work correctly in that it
wouldn't detect any fds that ${max} would need to be set higher than.
Thumbs up.

I don't know what systems don't support named pipes. MSYS2 MSYS makes
do with what Windows File Explorer recognizes as a shortcut with no
target and a code in the Comment field. In any case, if the system
supports named pipes to begin with, bash will support process
substitutions.



reply via email to

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