#!/usr/bin/env bash
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
function ctrl_c() {
echo
echo "** Trapped CTRL-C: Skipping Current Task **"
echo
}
function ping1 () {
sudo ping 8.8.4.4
sudo ping 1.1.1.1
}
function ping2 () {
sudo ping 8.8.8.8
}
function ping3 () {
sudo ping 8.8.4.4
}
ping1
ping2
ping3
My issue is that when I do ctrl c, it stops only the line being executed and I want it to skip the function as a whole and continue to the next function
An example is when I'm in ping1 and the first ping command sudo ping 8.8.4.4
is being executed. When I press control C, I want the script to proceed to ping2 instead of doing sudo ping 1.1.1.1