Bash Signal 0 in Trap Command – Explanation and Usage

bashsignalstrap:

I'm following this guide on how to set up passwordless SSH authentication with ssh-agent.

To start up ssh-agent the author recommends the following code in .bash_profile:

SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
    eval `$SSHAGENT $SSHAGENTARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

I don't understand why it is trapping signal 0. According to man 7 signal there is no such signal.

Is this just a typo or bug or does this really achieve something?

Best Answer

From the bash manual:

trap [-lp] [[arg] sigspec ...]

... If a sigspec is EXIT (0) the command arg is executed on exit from the shell.

Related Question