[Pkg-sysvinit-devel] Strange redirection in mountnfs.sh

Thomas Hood jdthood at yahoo.co.uk
Fri Jan 6 10:14:08 UTC 2006


Miquel van Smoorenburg wrote:
> On Thu, 2006-01-05 at 12:20 +0100, Thomas Hood wrote:
>> In mountnfs.sh, after reading through fstab, the script does the following:
>> 
>>     exec 0>&1
>> 
>> That is, file descriptor 0 (stdin) is made a copy of file descriptor 1 (stdout)!
>> 
>> I don't understand this.  Is it a mistake?
> 
> Nope. It undoes the redirection from /etc/fstab. In normal
> circumstances, filedescriptors 0, 1 and 2 are equivalent.


Aha.


> Also 0>&1 and 0<&1 are on all Unixes I know of equivalent


OK, so the choice of one or the other is a matter of style.


> It is nessecary to undo the redirection because you don't want to start
> portmap and mount with /etc/fstab on stdin.


OK.  I have already changed the script but it still undoes the redirection,
now in the manner of checkroot.sh, before starting portmap.


> The shells I know of do not create an extra process when you use ( ).


I just conducted an experiment.  I wrote the following little script "s":

    #!/bin/bash
    : ; sleep 10

While sleep is executing there are two processes listed by "ps -A": one s process
and one sleep process.  When I change the script to this:

    #!/bin/bash
    ( : ; sleep 10 )

(i.e., add parentheses ) then "ps -A" lists _two_ s processes and one sleep process.
So in this case bash does create a new process.  However, if the script is simplified
to this:

   #!/bin/bash
   ( sleep 10 )

then there is only one s process.  So it seems that bash creates a new process for
a list, but does not do so for a simple command.

Thanks for the tips.
-- 
Thomas



More information about the Pkg-sysvinit-devel mailing list