[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Backticked, nested command will steal piped stdin
From: |
Chet Ramey |
Subject: |
Re: Backticked, nested command will steal piped stdin |
Date: |
Thu, 1 Aug 2024 10:22:41 -0400 |
User-agent: |
Mozilla Thunderbird |
On 7/30/24 8:49 AM, Justus wrote:
Hello bash team!
I found a bug in my beloved bash and hope that you can fix it!
Everything else is described in the attached bashbug.txt
Word expansions like command substitution are run in the context of the
shell instance performing the expansion, which means that the child forked
to run the command substitution inherits things like open file descriptors
from its parent.
So if you have something like
seq 3 | head -n $(calc -dp "1+1")
the piping has already occurred by the time the child process forked to
run the final element of the pipeline performs the word expansion. If
the command substitution contains a process (like, apparently, `calc')
that reads from its stdin, it will consume the data and leave it
unavailable to its caller.
I suspect that zsh and fish act as you expect because they perform the
word expansion before making the pipe the standard input for the final
pipeline element.
--
``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/
OpenPGP_signature.asc
Description: OpenPGP digital signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Backticked, nested command will steal piped stdin,
Chet Ramey <=