The bash man page says
In output pertaining to jobs (e.g., the output of the jobs command), the current job is always flagged with a +, and the pre‐ vious job with a -. A single % (with no accompanying job specifica‐ tion) also refers to the current job.
In my bellow series of commands, after yes 2 > /dev/null & , I expected job [2] to be the current job not job[1].
Also at the end of the command yes 3 > /dev/null & I was expecting the jobs command output to be like this:
[1] Stopped
[2]- Running
[3]+ Running
what am I missing ?
$ yes 1 > /dev/null
^Z
[1]+ Stopped yes 1 > /dev/null
$ jobs
[1]+ Stopped yes 1 > /dev/null
$ yes 2 > /dev/null &
[2] 3082
$ jobs
[1]+ Stopped yes 1 > /dev/null
[2]- Running yes 2 > /dev/null &
$ yes 3 > /dev/null &
[3] 3116
$ jobs
[1]+ Stopped yes 1 > /dev/null
[2] Running yes 2 > /dev/null &
[3]- Running yes 3 > /dev/null &
Answer
From the same man page:
[…] the current job, which is the last job stopped while it was in the foreground or started in the background.
It's somewhat ambiguous. You may understand it as:
- Take all "jobs stopped while they was in the foreground or started in the background"…
- …then choose "the last".
But it's rather:
- Take "the last job stopped while it was in the foreground";
- but in case there's no such job, take "the last job started in the background".
No comments:
Post a Comment