Unix separate multiple commands which has '&' (execute in background) in the end

Well the ";" makes the shell wait for the command to finish and then continues with the next command.

The "&" will send any process directly into the background and continues with the next command - no matter if the first command finished or is still running.

So "&;" will not work like you expect.

But actually I'm unsure what you expect.

Try this in your shell:

sleep 2 && echo 1 & echo 2 & sleep 3 && echo 3

it will output: 2 1 3

Now compare it with

sleep 2 ; echo 1 & echo 2 & sleep 3 ; echo 3

which will output 1 2 3

Regards.


command1 & command2 Will execute command1, send the process to the background, and immediately begin executing command2, even if command1 has not completed.

command1 ; command2 Will execute command1 and then execute command2 once command1 finishes, regardless of whether command1 exited successfully.

command1 && command2 will only execute command2 once command1 has completed execution successfully. If command1 fails, command2 will not execute.

(...also, for completeness...)

command1 || command2 will only execute command2 if command1 fails (exits with a non-zero exit code.)