0

Suppose test.sh is a bash script that is empty or contains only exit 0. When the script is backgrounded, what is the significance of the 1 and 16320 printed to the console?

b@sam:~/Documents/bashscripts$ ./test.sh &
[1] 16320
b@sam:~/Documents/bashscripts$ 
[1]+  Done                    ./test.sh
b@sam:~/Documents/bashscripts$ 

Then if user hits ENTER at the command prompt, as illustrated above, another line appears and it shows this

[1]+ Done ./test.sh

What is the significance of the 1 digit and the + symbol?

2

[1] is the background job number, used for shell builtin commands like fg and bg which manage multiple tasks running in the same shell. jobs lists the current jobs.

16320 is the process ID number of the task, useful if you want to kill it or similar.

[1]+ Done indicates the background process has exited. Since you requested to run it in the background with ./test.sh &, it didn't wait for it to finish before giving you a fresh prompt (even though it finished almost immediately). The shell therefore notifies you the next time it gives you a prompt.

The + indicates the current (most recent) job, if you have multiple jobs running.

See the bash manual for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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