Send SIGINT to a command launched inside bash script
0
votes
0
answers
2181
views
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.
Asked by juvor
(149 rep)
Oct 2, 2020, 02:17 PM
Last activity: Oct 2, 2020, 04:00 PM
Last activity: Oct 2, 2020, 04:00 PM