What is the difference between running following commands on terminal?
command1
for i in {1..3}; do ./script.sh >& log.$i & done
and
command2
for i in {1..3}; do ./script.sh >& log.$i & done &
Running the first command shows three job IDs on the screen and I can type the next command on ther terminal.
The second command is a bit weird, it does not show any job IDs on screen nor can I see them after running jobs
command. Where did the jobs go?
Inside of script.sh I have following loop
for k in 1; do
./tmp -arguments
done
echo "hello"
If I use command 1, I can see via htop
that ./tmp
executible is running and echo "hello"
has not yet been executed (not in the log file).
If I use command 2, I can see via htop
that ./tmp
executible is running AND echo "hello"
has ALREADY been executed (as seen in the log file).
Why would an &
on the terminal change the behaviour of the for loop inside the shell script?
[GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)]