56

If I start a process with an ampersand (&) at the end, it'll be forked to background. When it finishes, I get an output similar to

[1]+  Fertig   my_script

I have a localized distribution, but this shouldn't matter.

What I see is the job ID in square brackets followed by a plus (+).

If I have multiple jobs started in parallel, I get

[1]-  Fertig   my_script
[2]+  Fertig   my_script

Now I have a minus (-) for the fist job and a plus (+) for the second one.

I wonder, what those +/- mean.

Couldn't find any answer using internet search engines.

1 Answer 1

72

From man bash:

In output pertaining to jobs (e.g., the output of the jobs command), the current job is always flagged with a +, and the previous job with a -.

That is, the job flagged with a + is the one that was sent to the background last.

It is also the one that will be brought into the foreground when fg is used without arguments:

$ /tmp/script &
[1] 9871
$ /tmp/script2 &
[2] 9876
$ /tmp/script3 &
[3] 9881
$ /tmp/script4 &
[4] 9886
$ jobs
[1]   Running                 /tmp/script &
[2]   Running                 /tmp/script2 &
[3]-  Running                 /tmp/script3 &
[4]+  Running                 /tmp/script4 &
$ fg
/tmp/script4

The job flagged with a - was sent to the background second last. Other background jobs are not flagged.

4
  • 1
    So, the + is useful in saying what the fg/bg commands will do, but is the - useful for anything?
    – tsbertalan
    Jan 20, 2016 at 5:15
  • @tsbertalan I agree, I can't see any use for it. I find it confusing, too, I'd rather expect the - to identify the job sent first to the background, but maybe it's just me...
    – jaume
    Jan 20, 2016 at 7:39
  • I sometimes see two pluses or two minuses there. Does not really fit the 'last' or 'current' definition. That's bash 4.3.42. Feb 15, 2016 at 19:16
  • 11
    @tsbertalan I do Ctrl+Z, then fg - to switch between two jobs. The minus sign comes in handy. Jul 6, 2016 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .