Skip to content

Instantly share code, notes, and snippets.

@ilatypov
Created November 4, 2016 15:53
Show Gist options
  • Save ilatypov/2d8d8043ef6592ebd6064906b773c6c7 to your computer and use it in GitHub Desktop.
Save ilatypov/2d8d8043ef6592ebd6064906b773c6c7 to your computer and use it in GitHub Desktop.
Demo the unstable bash 4.3.42 trap in the 64-bit Cygwin (cygwin1.dll of April 21, 2016, size 3539372) on Windows 7 Enterprise SP1
#! /bin/bash
set -e
function fun() {
echo fun called
}
trap '
err=$?
trap - HUP INT TERM EXIT ERR
# changing - to "" above stabilizes the trap
echo starting a trap loop
for ((i=0; i<10; i++)) ; do
echo trap loop
fun
sleep 1
done
exit $err
' HUP INT TERM EXIT ERR
while : ; do : ; done
# $ timeout 2s ./t.sh
# starting a trap loop
# trap loop
# fun called
#
# $ timeout 2s ./t.sh
# starting a trap loop
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
# trap loop
# fun called
@ilatypov
Copy link
Author

ilatypov commented Nov 4, 2016

Hmm just observed a "warning" when testing trap "",

$ timeout 2s ./t.sh
./t.sh: line 3: warning: run_pending_traps: bad value in trap_list[15]: 0x1
starting a trap loop
trap loop
fun called
trap loop
fun called
trap loop
fun called
trap loop
fun called
trap loop
fun called
trap loop
fun called
trap loop
fun called
trap loop
fun called
trap loop
fun called
trap loop
fun called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment