Bash – Why kill makes a bash script exit

bashkill

after the kill statement the script prints "Terminated" and the following lines never get executed:

#!/bin/bash

kill -9 `ps -ef | grep MailSender | grep -v grep | awk '{print $2}'`
echo starting
./MailSender

I have even tried to add set +e at the beginning but it still exits after kill.

Best Answer

Does the name of your script include MailSender? Try changing it, if so. Also, use pkill -9, it'll be cleaner:

#!/bin/bash

pkill -9 MailSender
echo starting
./MailSender