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

Support load .env into the current shell #19

Open
liudonghua123 opened this issue Aug 21, 2020 · 3 comments
Open

Support load .env into the current shell #19

liudonghua123 opened this issue Aug 21, 2020 · 3 comments

Comments

@liudonghua123
Copy link

I want to load .env into the current shell environment, does it support this feature?

@dkundel
Copy link
Owner

dkundel commented Aug 21, 2020

It sort of is. It's technically not the current shell environment but you could spawn a new shell using the tool. For example

npx node-env-run -e bash

This will open bash inside your current shell with the new environment variables applied. Similarly you could replace bash with whatever shell you want to run or even run:

npx node-env-run -e $SHELL

This would run a new shell with whatever you are already as your current shell.

Note This will spawn a new shell inside your shell. So it will look like you just successfully executed a command but in reality you are inside a shell inside your shell. Meaning once you are done with your work you should consider running exit to get out of the nested shell.

@dkundel
Copy link
Owner

dkundel commented Aug 21, 2020

Also if you just want to load in the .env file itself you can consider using source .env instead. This should just load them in.

@liudonghua123
Copy link
Author

You are right, I find it it difficult to change environment variables of parent process from the child process. The quick method for this maybe create a sub shell process.

Also source .env only works in Unix/Linux, does not work in Windows cmd or powershell.

https://unix.stackexchange.com/questions/372627/is-it-possible-to-pass-environment-variables-from-child-to-parent-in-user-space

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

No branches or pull requests

2 participants