[GLLUG] Shell scripting weirdness
mikey
abc.mikey at gmail.com
Thu May 23 09:37:01 UTC 2013
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
>
> --
> Alain Williams
> Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT
> Lecturer.
> +44 (0) 787 668 0256 http://www.phcomp.co.uk/
> Parliament Hill Computers Ltd. Registration Information:
> http://www.phcomp.co.uk/contact.php
> #include <std_disclaimer.h>
>
> _______________________________________________
> GLLUG mailing list
> GLLUG at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/gllug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20130523/e0953102/attachment.html>
More information about the GLLUG
mailing list