[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to get stdin from the parent process?
From: |
Pierre Gaston |
Subject: |
Re: [Help-bash] How to get stdin from the parent process? |
Date: |
Thu, 22 Feb 2018 16:56:44 +0200 |
On Thu, Feb 22, 2018 at 4:24 PM, Peng Yu <address@hidden> wrote:
> > you can save stdin in another fd that will be inherited, then redirect
> stdin
> > explicitely :
> >
> > #!/usr/bin/env bash
> > # vim: set noexpandtab tabstop=2:
> > exec 3<&0
> > (
> > while read -r i
> > do
> > echo "$i"
> > done
> > ) <&3 &
> > wait
>
> Thanks.
>
> In this specific case, I can move "<&3" into "()"? In other words, are
> the file handles shared by the parent and the child?
>
> My test case indicates so. But I want to make sure.
>
> exec 3<&0
> (
> while read -r i
> do
> echo "$i"
> done <&3
> ) &
> wait
>
> --
> Regards,
> Peng
>
Yes you can, all the file descriptors are generally inherited by the child
processes, what happens with stdin and & is an exception.