when I'm executing my bash-script, I'm getting the wrong PID. I'm needing the PID to kill the process at the end of it. This is a simplified script that is affected by the issue:
echo 'PASSWORD' | sudo -S ping -f '10.0.1.1' &
PING_PID=$BASHPID;
echo $PING_PID;
The output is for example
[1] 14336
PC:~ Account$ PING 10.0.1.1 (10.0.1.1): 56 data bytes
.
.PC:~ Account$..Request timeout for icmp_seq 18851
...
But when I'm looking to activity monitor (on Mac) I see that the ping-process has PID 14337, but why does the variable contains then 14336 and how to fix it?