I think that I have found a bug in dash that impacts EXIT trap handling. The behavior is different (and appears correct) in bash, ksh93 and mksh. I am using the EPEL dash package, version 0.5.10.2 for CentOS 7 (full package info included). I didn't see this already reported on the mailing list; hopefully I am not reporting a duplicate bug, sorry if so. The ssh-agent used in the context immediately below seems to prevent an EXIT trap from firing upon abnormal termination: # cat dashbug_trivial #!/bin/dash eval $(ssh-agent) trap 'eval $(ssh-agent -k)' EXIT if ssh-add then echo testing read junk fi The EXIT does not fire if the user aborts (it fires properly if the user does not abort): # ./dashbug_trivial Agent pid 59714 Enter passphrase for /root/.ssh/id_ed25519: Identity added: /root/.ssh/id_ed25519 (root@xxxxxxxxxxxxxxxxxxxxx) testing ^C # ps ax | grep agent | grep -v grep 59714 ? Ss 0:00 ssh-agent I am actually iterating over a set of hosts inside the conditional: # cat dashbug #!/bin/dash eval $(ssh-agent) trap 'eval $(ssh-agent -k)' EXIT if ssh-add then while read -r host port user <&9 do printf '=%s=%d=%s=\n' "$host" "$port" "$user" ssh -p "$port" "$user@$host" "$@" 2>&1 done 9<<-''EndOfHosts limsprd.amppcs.noa.alcoa.com 22 root darkstar.dpw.alcoa.com 24 root EndOfHosts fi The iterative script executes perfectly in dash; the problem is abnormal termination: # ./dashbug uptime Agent pid 10809 Enter passphrase for /root/.ssh/id_ed25519: Identity added: /root/.ssh/id_ed25519 (root@xxxxxxxxxxxxxxxxxxxxx) =host1.mycompany.com=22=root= 13:12:52 up 233 days, 1:58, 0 users, load average: 0.66, 0.63, 0.54 =host2.mycompany.com=24=root= 13:12:52 up 2 days, 1:59, 0 users, load average: 0.00, 0.00, 0.00 Agent pid 10809 killed Oddly, when I left off the trailing "fi" the trap killed the agent: # ./dashbug uptime Agent pid 9953 ./dashbug: 15: ./dashbug: Syntax error: end of file unexpected (expecting "fi") Agent pid 9953 killed When I break the password prompt with a control-c, dash does not terminate the agent: # ./dashbug uptime Agent pid 10072 Enter passphrase for /root/.ssh/id_ed25519: ^C # I confirmed this with a check of the process list: # ps ax | grep agent | grep -v grep 10072 ? Ss 0:00 ssh-agent If I switch this to mksh (or other previously mentioned shells), a control-c does what I expect: # head -1 dashbug #!/bin/mksh # ./dashbug uptime Agent pid 10193 Enter passphrase for /root/.ssh/id_ed25519: ^C Agent pid 10193 killed # Is this a problem with dash, or a lack in my understanding? These are the full details on the CentOS 7 EPEL package for dash: # rpm -qi dash Name : dash Version : 0.5.10.2 Release : 1.el7 Architecture: x86_64 Install Date: Wed 11 Aug 2021 01:45:26 PM CDT Group : System Environment/Shells Size : 159742 License : BSD and GPLv2+ and Public Domain and Copyright only Signature : RSA/SHA256, Mon 05 Nov 2018 06:00:50 AM CST, Key ID 72f97b74ec551f03 Source RPM : dash-0.5.10.2-1.el7.src.rpm Build Date : Mon 05 Nov 2018 06:00:48 AM CST Build Host : x86-ol7-builder-01.us.oracle.com Relocations : (not relocatable) Vendor : Oracle America URL : http://gondor.apana.org.au/~herbert/dash/ Summary : Small and fast POSIX-compliant shell Description : DASH is a POSIX-compliant implementation of /bin/sh that aims to be as small as possible. It does this without sacrificing speed where possible. In fact, it is significantly faster than bash (the GNU Bourne-Again SHell) for most tasks.