[GLLUG] Shell scripting weirdness

Alain Williams addw at phcomp.co.uk
Thu May 23 09:42:05 UTC 2013


On Thu, May 23, 2013 at 10:36:52AM +0100, mikey wrote:
> 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

You are right. Or use the following (all within the script):

    date | ksh -c 'exec 3<&0; cat <&3 & wait'

> 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.

Not needed (I don't think), but neat.

-- 
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