[GLLUG] Shell scripting weirdness

Alain Williams addw at phcomp.co.uk
Thu May 23 08:59:37 UTC 2013


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>




More information about the GLLUG mailing list