I am trying to make a script that runs 2 commands in a for loop as can be seen below:
#!/bin/bash
for ((i=0; i<2; i++)); do
sudo ./bin/llc test-rx -c 184
sleep 5
trap ctrl_c INT
function ctrl_c()
{
echo "Trap: CTRL+C received, exit"
exit
}
sudo ./bin/llc rxphylast
done
The 1st command (test-rx) continues to run as its is executed and it is stopped by pressing Ctrl+C. I want to stop this command in bash script so I used trap function as can be seen in the code. But when I execute the script, 1st command is running until I press Ctrl+C and then 2nd command (rxphylast) executes. So, in my case trap function is not working. Any advice on how to stop the 1st command in the script?