I tried to use asynchronous functionality in a bash script. It worked in a way. Here is the code.
echo "Process 1 lasts $1 seconds longer" && sleep $1 &
pid1=$!
echo "Process 2 lasts $2 seconds longer" && sleep $2 &
pid2=$!
wait $pid1
echo "Process 1 ended at $(date +%T) with exit status $? and pid $pid1"
wait $pid2
echo "Process 2 ended at $(date +%T) with exit status $? and pid $pid2"
But if I ran the script as ./script1.sh 8 2 , it doesn't print the completion of process2 after 2 seconds. After the completion of process 1, completion of both processes will be echoed out. Can someone show me what I am missing? I want it to echo the completion of a process at the moment it finished...