In a bash script I iterate through folders looking for some files, and if I find them I call a function with the directory that holds those files. See below
pairedread $1 & pairedread $2 & pairedread $3 & wait echo "Done ..." echo echo "======================" echo "Testing again" echo "======================" echo find . -type d -print | while read DIR; do echo "reading..." test -r "$DIR"/*_1.gz -a -r "$DIR"/*_2.gz || continue ( pairedread $DIR & ) done wait echo "Done..."
pairedread is the function that takes the folder and calls a python script on the files that are in the given directory. In the first case, ie when I explicitly give the folders that contain the files of interest, the script runs with instances of
pairedread executing and finally terminating followed with the helpful message
"Done..." after all subprocceses complete.
In the second case, the same three directories are picked and three instances of pairedread are created. However the script doesn't wait at all, it prints
"Done..." immediately and returns while the subprocesses are running in the background.
Am I missing something? Why can't I wait for the subprocesses to finish before going on with the script?