dash "set -e" breaks "trap INT"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux