When I try to execute mail
from inside a function in a bash script it creates something similar to a fork bomb. To clarify, this creates the issue:
#!/bin/bash
mail() {
echo "Free of oxens" | mail -s "Do you want to play chicken with the void?" "example@example.org"
}
mail
exit 0
Sometimes you can just kill the command and it'll kill the child processes, but sometimes you'll have to killall -9
.
It doesn't care whether the mail were sent or not. The fork bomb is created either way. And it doesn't seem as adding any check for the exit code, such as if ! [ "$?" = 0 ]
, helps.
But the script below works as intended, either it outputs an error or it sends the mail.
#!/bin/bash
echo "Free of oxens" | mail -s "Do you want to play chicken with the void?" "example@example.org"
exit 0
Why does this happen? And how would you go about checking the exit code of the mail command?