jobs command in dash doesn't work with pipes in scripts
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dash (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: dash
I have a script that uses "jobs | grep -c Running" in some nested loops to limit the number of parallel jobs that are running. When /bin/sh is set to dash, the script fails. When /bin/sh is set to bash the script works as desired. I can change the first line of the script to explicitly call /bin/bash instead of /bin/sh, but maybe dash should be changed as well. Here are two test scripts that demonstrate the problem:
dagger ~/job_count $ cat job_count.bash | sed -e "s/^/ /"
#!/bin/bash
sleep 10&
sleep 10&
printf "job list\n"
jobs
printf "jobcount = "
jobs | wc -l
printf "job list (piped through cat)\n"
jobs | cat
printf "job list\n"
jobs
wait
echo finished
dagger ~/job_count $ cat job_count.dash | sed -e "s/^/ /"
#!/bin/dash
sleep 10&
sleep 10&
printf "job list\n"
jobs
printf "jobcount = "
jobs | wc -l
printf "job list (piped through cat)\n"
jobs | cat
printf "job list\n"
jobs
wait
echo finished
Here's the output from the bash script. Notice jobcount=2 and the jobs output appears when piped through cat.
dagger ~/job_count $ ./job_count.bash | sed -e "s/^/ /"
job list
[1]- Running sleep 10 &
[2]+ Running sleep 10 &
jobcount = 2
job list (piped through cat)
[1]- Running sleep 10 &
[2]+ Running sleep 10 &
job list
[1]- Running sleep 10 &
[2]+ Running sleep 10 &
finished
Here's the output from the dash script. Notice jobcount=0 and the jobs output does not get piped through cat.
dagger ~/job_count $ ./job_count.dash | sed -e "s/^/ /"
job list
[2] + Running
[1] - Running
jobcount = 0
job list (piped through cat)
job list
[2] + Running
[1] - Running
finished
I would expect the output from the bash and dash scripts to be the same. Specifically the dash script should print "jobcount = 2" and should list the two running jobs immediately after "job list (piped through cat)".
I'm using a clean install of ubuntu 8.04.
dagger ~/job_count $ dpkg -s dash|grep Version
Version: 0.5.4-8ubuntu1