Normally, in a bash script, exec
replaces the bash process, and the rest of the script is ignored:
#!/bin/bash
exec command1
command2 # will not execute
However, if we add &
after the exec
line, it will continue to run:
#!/bin/bash
exec command1 &
command2 # will execute
It seems totally equivalent to a non-exec
script which simply puts command1
to background:
#!/bin/bash
command1 &
command2 # will execute
Is it really no difference between using and not using exec
on a background command?
Will it be faster or slower if using exec
?