sorry I cannot figure out what is wrong with the following. When I hit ctrl-c in a script the trap works, but does not when the script is source executed.
Example (test2.sh):
#!/bin/bash
ctrl_c()
{
echo "user canceled."
}
trap ctrl_c INT
sleep 500
trap - INT
The following happens:
[root@localhost ~]# ./test2
^Cuser canceled.
[root@localhost ~]# . test2
^C
This is RHEL 7, Bash 4.2, but the same problem is also happening in other Linux distributions and also Bash 4.4.
Please help. Thanks!