Friday, 4 January 2019

command line - The "+" and "-" signs next to the job number


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:



  1. Take all "jobs stopped while they was in the foreground or started in the background"…

  2. …then choose "the last".


But it's rather:



  1. Take "the last job stopped while it was in the foreground";

  2. but in case there's no such job, take "the last job started in the background".


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...