I've been experimenting with backgrounding in bash scripts, and I cannot seem to get it to call a script, background it, and move on without the completion of that script.
I have the following files:
caller.sh:
Code:
#!/bin/bash
`./called1.sh &`
`./called2.sh &`
exit
called1.sh:
Code:
#!/bin/bash
i=0
while [ "$i" -lt 5 ]
do
echo "ONE" > /dev/tty
sleep 5
i=`expr $i + 1`
done
called2.sh:
Code:
#!/bin/bash
i=0
while [ "$i" -lt 5 ]
do
echo "TWO" > /dev/tty
i=`expr $i + 1`
done
The intention was such that when I execute caller.sh, it would then execute called1.sh in the background and THEN execute called2.sh immediately (without waiting for called1.sh to finish). If this would happen, I should expect the following result:
Code:
#./caller.sh
ONE
TWO
TWO
TWO
TWO
TWO
ONE
ONE
ONE
ONE
..but instead, I receive the following output:
Code:
#./caller.sh
ONE
ONE
ONE
ONE
ONE
TWO
TWO
TWO
TWO
TWO
This indicates to me that the caller.sh script is not backgrounding the called1.sh script. Instead, it waits until the caller1.sh script finishes and THEN it calls caller2.sh.
What must I do to make it run the two scripts at once such that I obtain the former of the two outputs? Any help will be appreciated.
Thanks in advance.