DASH Shell discussions
 help / color / mirror / Atom feed
* dash "set -e" breaks "trap INT"
@ 2010-11-10 13:49 Dan Muresan
  2010-11-13 21:05 ` Jilles Tjoelker
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Muresan @ 2010-11-10 13:49 UTC (permalink / raw)
  To: dash

Hi,

I've submitted a bug regarding trap + "set -e" on Ubuntu Launchpad
[1], but that's probably not the best place to talk about the issue.

I'm using dash 0.5.5.1-3ubuntu2 from Ubuntu Lucid on an x86 machine.
With "set -e", only the first command in an INT trap handler gets
executed -- UNLESS that first command is a call to a function that
returns 0. Here's an example of the problem:

--- 8-x ---

#!/bin/sh
set -e

trap 'hnd' INT
trap 'echo EXIT' EXIT

zero() {
  return 0;
}

hnd() {
  #zero
  echo "Ignored 1"; echo "Ignored 2"
  sleep 1
  echo Back
}

for i in 3 2 1; do
    echo "$i"
    sleep 1 # || true
done

echo OUT

--- 8-x ---

If we uncomment either the call to zero, or the || true check, the
entire handler gets executed. A set +e inside the handler makes no
difference.

My workaround at the moment is to trap both INT and EXIT (I'm not
going to rely on the "zero" bit of magic). I suppose this workaround
will unfortunately have to stick around for a while -- even if this
bug gets fixed, scripts can't assume they are running on the latest
version of dash.

[1] https://bugs.launchpad.net/ubuntu/+source/dash/+bug/673119

-- Dan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-11-13 21:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-10 13:49 dash "set -e" breaks "trap INT" Dan Muresan
2010-11-13 21:05 ` Jilles Tjoelker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox