Collecting process ids of parallel process in bash file
问题 Below I have a script that is collecting the process ids of individual commands, and appending them to an array in bash. For some reason as you can see stdout below, the end resulting array just contains one item, the latest id. How can the resulting PROCESS_IDS array at the end of this script contain all four process ids? PROCESS_IDS=() function append { echo $1 PROCESS_IDS=("${PROCESS_IDS[@]}" $1) } sleep 1 && echo 'one' & append $! & sleep 5 && echo 'two' & append $! & sleep 1 && echo