I realized that the following loop in a bash script will send ./a.out to background, and the run will return to the system before even a single ./a.out running is done.
#!/bin/bash
for i in 1,2,3
do
echo $i
./a.out
done
The question is how to let the next bash loop wait until “./a.out” is done?
BTW, I thought this should be a common problem but didn’t find similar questions, or I may need more searching skills…
What you’re describing is the default behavior. You might be confused by the fact that your loop only runs once, with
i="1,2,3", and therefore appears to print all at once and then exit immediately.Try
for i in 1 2 3instead, and see if you get the output you expect.