Dash man page error regarding: background commands and the redirection of standard input to /dev/null

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



While writing a script, I wanted a background command to be able to
read from standard input.  (Specifically, from the terminal.)

While trying to achieve this result, I believe I found an error in the
dash man page.

The dash man page says:

   Background Commands -- &
     If the shell is not interactive, the standard input of an asynchronous
     command is set to /dev/null.

Source:
https://git.kernel.org/pub/scm/utils/dash/dash.git/tree/src/dash.1#n583
(Specifically, see line 592.)

I believe the above is incorrect.  I believe it is the 'monitor'
option flag that determines whether or not standard input is
redirected.

Below is a script that exposes the actual (and correct?) behavior.

I have tested the script with:
dash 0.5.11.4-1 on Arch
dash 0.5.10.2-6 on Ubuntu

----

PS1='$ '

probe  ()  {
  [ -t 0 ]  &&  s0='0'  ||  s0='1'
  [ -t 1 ]  &&  s1='0'  ||  s1='1'
  [ -t 2 ]  &&  s2='0'  ||  s2='1'
  echo  "probe.$1  $s0 $s1 $s2"  ;  }

echo  ;  echo  'plain'
probe  1
probe  2  &  wait
sleep  1

echo  ;  echo  'set  -o monitor'
set  -o monitor
probe  3
probe  4  &  wait
sleep  1
set  +o monitor

echo  ;  echo  'set  -o interactive'
set  -o interactive
probe  5
probe  6  &  wait
sleep  1
sleep  1

----

Actual output:

plain
probe.1  0 0 0
probe.2  1 0 0

set  -o monitor
probe.3  0 0 0
probe.4  0 0 0
[1] + Done                       probe 4

set  -o interactive
$ probe.5  0 0 0
$ probe.6  1 0 0
$ $ $

----

In the above, probe.4 and probe.6 do not behave as described by the
dash man page.

If the dash man page were correct, probes 4 and 6 would echo the
following output:
probe.4  1 0 0
probe.6  0 0 0

----

To compare with bash, the bash man page says:

       If a command is followed by a & and job control is not active, the  de‐
       fault standard input for the command is the empty file /dev/null.  Oth‐
       erwise, the invoked command inherits the file descriptors of the  call‐
       ing shell as modified by redirections.

----

When run with bash, the above test script behaves as described in the
bash man page.

----

plain
probe.1  0 0 0
probe.2  1 0 0

set  -o monitor
probe.3  0 0 0
probe.4  0 0 0

set  -o interactive
test.sh: line 23: set: interactive: invalid option name
probe.5  0 0 0
probe.6  1 0 0

----

Observations:

1)  It appears that the 'monitor' option flag controls the redirection
of standard input for background commands.  This is true in both dash
and bash.

2)  Whereas: The dash man page (incorrectly?) says that only the
'interactive' option flag controls redirection of standard input for
background commands.

3)  dash (surprisingly?) allows run-time toggling the interactive
option flag.  (bash does not.)

4)  (Surprisingly?) 'set -o monitor' causes dash to print out '[1] +
Done probe 4' even when the interactive action flag is not set.  (bash
does not print out this 'Done' message.)

5)  If the interactive option flag is toggled on at run-time, dash
echos PS1 after every command.  (Whereas bash does not allow run-time
toggling of the interactive option flag.)

6)  Assuming dash's current behavior is correct (i.e. redirecting
standard input based solely on the monitor option flag), then I
recommend updating the dash man page so it accurately describes the
current behavior.




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux