It's a matter of timing: bash launches the
hello command in the background, then it displays a prompt to let you enter a new command, then the background command prints some output. When you enter the next command line (an empty command line, if you just press Enter), bash displays the notification that the background job has finished, then the next prompt.
You may want to experiment with a script that starts with
sleep 3 and start typing just after launching the script in the background, to see what's happening at a pace you can follow.
You can make bash notify you immediately when a background job terminates by setting the
notify option with
set -b. Then you'll see:
$ set -b
$ hello &
$ hello world!
Bash doesn't redraw the prompt in this case. You're still editing a command line on the prompt line that appeared before the background job printed
hello world!. You can redraw the current line by pressing Esc 1 Ctrl+L. You may want to bind the command
redraw-current-line to a more convenient key; for example, to have Ctrl+L redraw the current line and Ctrl+Alt+L clear the screen, add the following lines to your
I don't know of a way to make bash redraw the prompt line automatically. Zsh does it by default.