Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Huh, I was skeptical, but I just confirmed you are right. Tested on a v3 bash as well as a BusyBox sh (variant of ash), works as you say in both cases. Commented Oct 1, 2015 at 20:27
  • Great thx, but there's still a little problem that I do not understand. 'trap '[ $? = 0 ] && exit;'"echo 'DUPA'" INT QUIT TERM EXIT </br> sleep 2 when I hit ctrl+c, i see 'dupa' printed twice. Why's that? Is trap handled twice then? When? Commented Oct 2, 2015 at 6:55
  • Yes, trap is called once for the sigint, then once for the exit. You can probably check if trap is being called from sigint as the $? will be 128+n where n is the signal, so 130 for sigint. Remember $? will be changed as soon as you give another command, so perhaps start with rc=$?; then use $rc. Commented Oct 2, 2015 at 7:16