Subject: Re: Bourne shell oddity
To: None <current-users@netbsd.org>
From: Christos Zoulas <christos@tac.gw.com>
List: current-users
Date: 06/23/2005 02:33:02
In article <20050622.134104.45734211.he@uninett.no>,
Havard Eidnes  <he@uninett.no> wrote:
>> Havard Eidnes wrote on 2005-06-21|16:35:
>> > -------------------- /tmp/x:
>> > #! /bin/sh
>> >
>> > echo x: before
>> > ( sh -c "sleep 60" ) > /dev/null 2>&1 </dev/null &
>> > echo x: after
>> > exit 0
>> > -------------------- /tmp/y:
>> > #! /bin/sh
>> >
>> > echo y: before
>> >
>> > l=`/tmp/x`
>> >
>> > echo y: after
>> > --------------------
>> >
>> > If you run "sh /tmp/y", the "y: after" output will not appear
>> > until 60 seconds has passed, i.e. the innermost background job
>> > finishes, even though that job has no chance of affecting the
>> > result due to the redirection.
>>
>> I don't think that's a bug. According to the sh(1) manpage, the
>> backquotes will be replaced by the output of the enclosed command.
>> But how can you get the complete output of the enclosed command
>> before it has finished?
>
>Please notice that the subshell doing the "sleep 60" is a
>background job, so the enclosing script should finish right away,
>as it does when run directly from the command line.  Also note
>that the subshell runs with stdout and stderr redirected.  That's
>two reasons the output of the backquoted command will not be
>affected.
>
>Also note that if /tmp/x is changed to a /bin/ksh or /bin/bash
>script, the "hang" does not happen, as is also the case if the
>sleep is not done in a subshell, i.e. the parenthesis are
>removed.

Try eval.c 1.83.

christos