I am executing a bash script and I want to correctly terminate a command (by pressing CTRL+C) that I am launching inside the script. This is the script:
trap ctrl_c SIGINT
function ctrl_c()
{
PID = $!
kill -s SIGINT -$PID
wait $PID
echo "mycommand stopped!"
}
mycommand directory -option | grep --line-buffered -A 'Hello|Bye' >> output
But it doesn't stop mycommand.