[GLLUG] Shell scripting weirdness

Robert McKay robert at mckay.com
Thu May 23 21:33:36 UTC 2013


Thanks guys.. That explains it.. I knew someone here would know :)

Cheers,
Rob

> But since writing "<&0" is equivalent to writing "0<&0" which is 
> effectively meaningless not many of the shells interpret it as 
> reconnecting input to stdin as bash does.
>
> Something like:  sh -c " cat <&3 3<&- & wait" 3<&0
>
> might be more portable.
>
> This information is taken from the link I posted rather than my own: 
> http://unix.stackexchange.com/questions/71205/background-process-pipe-input
>
> So I'm not exactly why you would need to close the input to file 
> descriptor 3 with "3<&-", left it in for good measure.
>
> (may have something to do with making it unavailable or the 
> subsequent commands.)



> On 23 May 2013 09:59, Alain Williams <addw at phcomp.co.uk> wrote:
>
>    On Wed, May 22, 2013 at 10:11:52PM +0100, Robert McKay wrote:
>    > Greetings fellow Lugites,
>    >
>    > I was wondering if anyone knows why these two commands behave
>    > differently;
>    >
>    > bash -c "cat & wait"
>    > bash -c "cat <&0 & wait"
>    >
>    > The first just exits right away. The second one does what I
>    > wanted/expected the first one to do.
>
>    Running something in background causes its stdin to be connected 
> to /dev/null.
>    Thus:
>
>    1) cat gets EOF immediately
>
>    2) cat has its stdin *reconnected* to bash's stdin and thus reads 
> whatever before
>       getting EOF





More information about the GLLUG mailing list