Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

EXIT traps that print to stdout shouldn't break process substitution #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

onlynone
Copy link

@onlynone onlynone commented Jun 7, 2018

OS X sets a trap on EXIT to call shell_session_update, this calls shell_session_save which will print to stdout. Normally this is not a problem for subshells instantiated like $(...), because the traps are apparently not inherited by (at least these types of) subshells. However, rvm re-installs this trap, (even from within subshells) when you call something like cd (which rvm overrides).

Basically:

trap 'echo trapped' EXIT
a=$(echo a)

Will not have the EXIT trap called inside the $(...), and will result in a=a. However:

a=$(trap 'echo trapped' EXIT; echo a)

Will have the trap called, and will result in a=a trapped.

The latter is what rvm ends up doing when it's loaded by its version of cd, and you do something like:

a=$(cd somewhere && pwd)

Perhaps the overridden shell commands should never install the exit trap? Or rvm could detect when it's being run inside a subshell where it's helpers aren't needed and not run any of the init code?

@onlynone
Copy link
Author

onlynone commented Jun 7, 2018

This test failed, only because there's a bug with rvm.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant