[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: access the stdin of the parent process in a pipeline
From: |
Chet Ramey |
Subject: |
Re: access the stdin of the parent process in a pipeline |
Date: |
Wed, 25 Mar 2020 09:26:21 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
On 3/25/20 8:45 AM, Peng Yu wrote:
>> function g1 {
>> seq 3 | awk -e 'BEGIN { while(getline < "/dev/stdin") print } {
>> print }' /dev/fd/4
>> } 4<&0
>>
>> $ seq 4 | g1
>> 1
>> 2
>> 3
>> 1
>> 2
>> 3
>> 4
>
> I never knew that I could add redirection after the function
> declaration. This is neat.
Yes. A function declaration is a compound command, and compound commands
may be followed by redirections.
POSIX specifies that the shell processes any redirections following a
function declaration when the function is executed.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/