Comment 4 for bug 673119

Revision history for this message
Jarno Suni (jarnos) wrote :

Output by dash 0.5.10.2-6:
3
^CIgnored 1
Ignored 2
Back
EXIT

bash 5.0.3 works the same way.

To get the output you want, you can use the following code:
--------------
#!/bin/sh
#set -e

trap '' INT
trap 'echo EXIT' EXIT

sorry() {
  echo "Ignored 1"; echo "Ignored 2"
  sleep 1
  echo Back
}

for i in 3 2 1; do
    echo "$i"
    (
  trap 'sorry; exit 0' INT
  sleep 1
    ) # || :
done

echo OUT
---------

If you use bash, instead of dash, it would work even if "set -e" was used and "trap '' INT" was not used. If "set -e" was used with dash, you would have to uncomment "|| :" to make it work.

See also Bug #892317