bug-bash
[Top][All Lists]
Advanced

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

Re: jobs -p falsely reports the last background pid


From: Greg Wooledge
Subject: Re: jobs -p falsely reports the last background pid
Date: Wed, 9 Apr 2014 08:04:17 -0400
User-agent: Mutt/1.4.2.3i

On Wed, Apr 09, 2014 at 12:43:40PM +0200, Håkon Bugge wrote:
> This script never terminates:
> --------------------------------------------------
> #!/bin/bash 
> 
> for P in `seq 5`; do 
>     sleep 1&
> done
> 
> while true; do
>     usleep 20000
>     set foo `jobs -p`
>     LEFT=$#
>     LEFT=$[LEFT-1]
>     echo $LEFT jobs left
>     if [ x$LEFT = x0 ]; then
>       break
>     fi
> done

>    Pasting the same commands in an interactive shell, its works.

Interactive shells enable job control (monitor mode), whereas
noninteractive shells (scripts) do not.  If you want to use job control
commands (like "jobs") within a script, you must enable monitor mode
(set -m, or set -o monitor, or #!/bin/bash -m).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]