When running the following script in OSX using bash version 3.2
#!/bin/sh
set -e
function _trap_exit {
echo "this is a triggered trap..."
}
trap _trap_exit EXIT
/usr/sbin/ioreg -w0 -l | grep ExternalChargeCapable | grep -q No
echo "Final statement"
I get a trap triggered. But if I change the final grep statement to Yes ie grep -q Yes
then the trap isn't triggered.
Any idea why this is happening and how to stop it? Why should the exit code from grep cause a trap to be triggered?
EXIT
signal, the trap will always be triggered.set -e
which I had copy/pasted which caused the the problem... See my answer...