For example:
$ cd ~/code/someFolder ~/code/someFolder$ gitk --all& # launches a gtk window of gitk [1] 9335 # what is this in the first place
now I go do some work inside the gtk window, then close it
~/code/someFolder$ echo 'foobar' foobar [1]+ Done gitk --all # this extra output
I have an inkling that the ampersand is somehow 'holding' the process and closing it in gtk ends the process resulting in the output... but that's a very unscientific explanation.
PS: Sorry about the unwieldy question, I couldn't think of a better way to express it.
In your question, there are some misconceptions. Firstly, this behavior is not limited to Gtk commands. Secondly, the notification is not send after the "next command" but on the next prompt (say, as soon as you type the Enter key).
What you are doing is called Job Control. In bash you can send commands to the "background" so that they don't block the command line. For example, try running
gedit
on the terminal. Gedit's window should appear and the command line should be "blocked", that is, you cannot type any new command unless you close Gedit.A solution to this blocking behavior of "long running" processes is to send their commands to the background on invocation. This way the command won't block and you will be able to continue working on the command line.
A way to send a command to the background is by using the
&
after the command. Continuing with the Gedit example, you can start it on the background by runningYou will now notice that the command prompt is printed immediately and you can run new commands (contrast this with simply running
gedit
without ampersand). You'll also notice the extra information about the new "job" you just created: the job number in brackets, and its PID.When the job ends (either normally or because you killed it), bash will notify you with something similar to:
(The
1
is the job number and on the right you have the command with which you created this job, just in case you forgot :-)If you have several jobs on the background you can use the command
jobs
to get a list with their statuses.In conclusion, you don't need to add the ampersand unless you want to run another command immediately.
For references and other interesting aspects about job control read: