Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I am running background processes like(I have 9 files suffixed by phastcon):

for i in *.phastcon; do cut -f 2 $i >$i.value & done

After kicking the "Enter", I get the output in terminal showing background id and process id,

[1] 22917
[2] 22918
[3] 22919
[4] 22920
[5] 22921
[6] 22922
[7] 22923
[8] 22924
[9] 22925

But hen finished, I got

[7]   Done                    cut -f 2 $i > $i.value
[8]-  Done                    cut -f 2 $i > $i.value
[1]   Done                    cut -f 2 $i > $i.value
[2]   Done                    cut -f 2 $i > $i.value
[3]   Done                    cut -f 2 $i > $i.value
[4]   Done                    cut -f 2 $i > $i.value
[5]   Done                    cut -f 2 $i > $i.value
[6]-  Done                    cut -f 2 $i > $i.value
[9]+  Done                    cut -f 2 $i > $i.value

The results are all right.

But I can not understand what is the difference of '-' and '+' after the square.

Thank you for all helps!

Tong

share|improve this question
    
A question: what is $i.value? –  neurino Jul 25 '12 at 7:43
    
@neurino The output file –  Bernhard Jul 25 '12 at 7:55
    
ok, I just guessed if there was in Bash some kind of dotted notation like javascript for variables :) .value is only the file extension ^^ –  neurino Jul 25 '12 at 8:17

1 Answer 1

up vote 3 down vote accepted

From the bash manpage, in the section "JOB CONTROL":

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 -.

This explains the + behind the [9], because that was the last job started. It also explains the - behind [8] and [6], because they were the previous jobs at the moment they finished ([6] was the previous job because [7] and [8] finished before it).

share|improve this answer
    
thanks. i'd never spotted that in the bash man page, but it matches what i'd figured out long ago. nice to know that it's "official". –  cas Jul 25 '12 at 7:10
    
Thank you! Great answer. If the completion order of jobs is the same as the task allocation order, then no '-' will show. If a job costs longer time than the one started later, a '-' will add when finished. Do I get it? And also I wonder why these two operators are needed? Usually I will not care them. –  ct586 Jul 25 '12 at 7:21
2  
@ct586 I find those useful when switching between jobs. The + indicated the last active job, the - the one before it. So if you started three jobs and did nothing about them, you'd have [1] [2]- [3]+. However, if you put job 2 in the foreground and the background again, you'd have [1] [2]+ [3]-. It can help determine which job was put in the foreground last, making it easier to switch. But there is more to the story, as the above answer shows and that's just one use case. –  Wojtek Rzepala Jul 25 '12 at 7:42
    
@Wojtek Rzepala Thanks for the wonderful example. My understand of '-' and '+' is wrong. I get it. –  ct586 Jul 25 '12 at 8:35
1  
note also that the + and - can and will change position if you run several jobs and manually suspend/foreground them. e.g. i tend to have lots of 'mutt -f /path/to/mbox' running and use ^Z to suspend & 'fg 1', 'fg 10', etc to switch between my frequently used mboxes. i.e. they don't indicate the two most recently started jobs, but the current and previous jobs. –  cas Jul 25 '12 at 10:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.