Recently I encountered a problem in ubuntu upstart and trap in Bash shell.I use ubuntu 12.04. The upstart script(/etc/init/player.conf) is:start on (local-filesystems and runlevel [2345])stop on runlevel [06]script    /tmp/test.shend scriptThe /tmp/test.sh is:#!/bin/bashTOKEN=tokenTOKEN_FILE=/tmp/tokenOUTPUT_FILE=/tmp/test_exitfunc(){    grep $TOKEN $TOKEN_FILE; echo $? >> $OUTPUT_FILE; exit 0}trap 'trap  INT TERM QUIT EXIT; func' INT TERM QUIT EXITrm -f $OUTPUT_FILEecho $TOKEN > $TOKEN_FILEgrep $TOKEN $TOKEN_FILE; echo $? >> $OUTPUT_FILE;sleep 1000exit 0The test procedure:$sudo service player start$sudo service player stop$cat /tmp/test_exit02My question is, why the second result is 2, since the file(/tmp/token) is not changed, the grep should find the string(token) in that file(/tmp/token). 
exit code of grep in trap where the script is launched by upstart service
bash;ubuntu;grep;upstart;trap