I know I can run a program in the background using &
.
command &
However, I want to run multiple commands, and cd
into a different directory while they are running.
The multiple commands will still rely on the directory I was previously in.
I've tried the following, but it only runs the last command in the background:
command1 && command2 &
Doing this gives a parse error:
command1 & && command2 &
It's important that command1
finishes before command2
,
so I don't think the following would guarantee that:
command1 &; command2 &;
I'm not tied to any specific shell.
Best Answer
(command1; command2)&
- should do it, works in bash.This creates a subshell (the two parenthesis) and runs the whole subshell in the background.