Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exporting CDPATH to subshell could be harmful on macOS #251

Open
anpol opened this issue Feb 10, 2017 · 2 comments
Open

exporting CDPATH to subshell could be harmful on macOS #251

anpol opened this issue Feb 10, 2017 · 2 comments

Comments

@anpol
Copy link

anpol commented Feb 10, 2017

To reproduce, execute the following script on macOS:

#!/usr/bin/env bash

mkdir test; cd test
mkdir foo bar 2>/dev/null

cat <<END >.envrc
export CDPATH=foo:bar:baz
END

direnv allow .

eval "$(direnv export bash)"

# The following /bin/sh script could fail.
/bin/sh <<END
echo bash "$BASH_VERSION"
cd foo
cd ../bar
END

This script fails with the following output:

direnv: loading .envrc
direnv: export +CDPATH
bash 3.2.57(1)-release
/bin/sh: line 2: cd: foo: No such file or directory
/bin/sh: line 3: cd: ../bar: No such file or directory

On macOS, /bin/sh is the bash version 3.2, incorrectly handling CDPATH environment variable, as described here: http://unix.stackexchange.com/a/112364cd command just fails as above.

The solution could be to prevent exporting CDPATH to subshells, as it's not of much use of it out of interactive shell.

But with direnv it's not possible to define a variable without exporting it.

I suggest handling CDPATH in a special way, allowing it to be exported from .envrc, but preventing it to be further exported to subshells. What I mean is that $(direnv export) should output just CDPATH=... without the export qualifier.

@anpol
Copy link
Author

anpol commented Feb 17, 2017

@zimbatm
Copy link
Member

zimbatm commented Mar 11, 2017

Interesting. I have another variable that would best be set instead of exported: PS1.

Direnv doesn't really have a mechanism for that. If I get around to rewrite direnv I will take that into account.

@zimbatm zimbatm added this to the direnv 3 milestone Mar 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants