Sample Header Ad - 728x90

trap is ignored when dialog is running with custom BASH_XTRACEFD

3 votes
3 answers
231 views
I have following script
#!/bin/bash

exec 5> >(logger -t $0)
BASH_XTRACEFD="5"
set -x

trap _reboot INT

DIALOG_TITLE="This is fancy dialog title"

_reboot() {
        echo Exiting
        exit
}

dialog --title "${DIALOG_TITLE}" --yesno "Welcome to Dialog" 0 0
However when i do CTRL+C, script is exited without printing anything. If i remove either set -x or BASH_XTRACEFD="5" it will work fine and trap is caught and _reboot function is executed. But if i leave both in (which i need for debugging purposes) - then trap looses all meaning. Exit code is 141 which is interesting when i exit with CTRL+C. If i let the script run it's natural course it will exit with 0 However if i remove either of set -x or BASH_XTRACEFD="5" and then CTRL+C i will exit with 55 then. This for some reason happens only while dialog is on screen. For example if i do
while true; do
  sleep 5
done
And then exit with CTRL+C trap will be executed. I need help figuring this thing out. EDIT: Might be worth mentioning that bash version is 5.1.16, running on Alpine 3.16
Asked by Marko Todoric (437 rep)
Jul 4, 2022, 11:06 AM
Last activity: Apr 20, 2025, 09:57 AM