I have this bash script:
#!/bin/bash
if [ "$#" -eq 4 ]
then
rep_origine="$1"
rep_dest="$2"
temps_exec="$3"
temps_refr="$4"
else
echo "Usage : $0 [files directory] [destination directory] [execution time$
exit 2
fi
cp -R "$rep_origine" "$rep_dest" &
cp_process="$!"
while [ "$cp_process" -eq "$!" ]
do
cp_process="$!"
sleep "$temps_exec"; kill -STOP "$cp_process"
sleep "$temps_refr"; kill -CONT "$cp_process"
done
I would like my loop to end when the cp command ends. Therefore, I put that when the last PID was not the same as the PID of cp, the loop should end but it does not work.
I don't see how to indicate that the loop should end when the cp command ends.