I have a script such as follows:
for ((i=0; i < $srccount; i++)); do
echo -e "\"${src[$i]}\" will be synchronized to \"${dest[$i]}\""
echo -e $'Press any key to continue or Ctrl+C to exit...\n'
read -rs -n1
rsync ${opt1} ${opt2} ${opt3} ${src[$i]} ${dest[$i]}
done
If I press Ctrl+C in response to read command, the whole script will stop, but if press Ctrl+C while rsync command is running, just current rsync command will stop and the script will continue the for loop.
Is there any way to tell the script if the user pressed Ctrl+C while rsync is running, stop rsync and exit from the script itself?
opt1,opt2,opt3,srccount,srcanddestare defined in the previous line of the script.trap "exit" INT. See unix.stackexchange.com/a/48432/50240