Note that this is the same as the original bash implementation, and fixes the terminal even on segfaults.
See https://gitlab.esss.lu.se/e3/wrappers/e3-require/-/blob/5.0.0/require-ess/tools/iocsh_functions.bash#L144