Re: Inconsistent behaviour between 'jobs' and 'echo "$(jobs)"'

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

 



On 01/20/2015 09:44 AM, Seb wrote:
On Mon, Jan 19, 2015 at 07:01:53PM +0100, Damian Wrobel wrote:

Hello,

I'm observing an inconsistent behaviour between:
  jobs
and
  echo "$(jobs)"

It's because the command is ran in a sub-shell, where there is indeed no
running job.

Bash has a special mechanism to handle this and get the current shell
context returned, that's why you may feel some inconsistency here (like
I myself did :)

There is an application usage [1] where this case is specifically mentioned with a suggestion that: "For this reason, jobs is generally implemented as a shell regular built-in."

I basically planned to use the following construction to kill all running jobs:

$ kill $(jobs -p)

Now it looks that even the following doesn't work in a dash:

$ jobs -p | xargs kill

I would prefer not to code something like the following:

$ jobs -p >/tmp/jobs-$$ && kill $(cat /tmp/jobs-$$); rm /tmp/jobs-$$


Have a nice day,
Damian

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/jobs.html


++
Seb.




--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



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

  Powered by Linux