[SERVER-4895] Expose environment variables in the shell Created: 07/Feb/12 Updated: 06/Dec/22 Resolved: 19/Nov/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Scott Hernandez (Inactive) | Assignee: | Backlog - Server Tooling and Methods (STM) (Inactive) |
| Resolution: | Won't Fix | Votes: | 12 |
| Labels: | move-stm, neweng, platform-lhf | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Assigned Teams: |
Server Tooling & Methods
|
||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
Something like
|
| Comments |
| Comment by Orgad Shaneh [ 21/Apr/21 ] | ||
|
_getEnv function was added inĀ | ||
| Comment by Matt Kalan [ 24/Feb/17 ] | ||
|
This came up in a Docker setup this week (on Windows) which I think might make this requirement increasingly more common, as often configuration will be scripted and parameters passed in dynamically | ||
| Comment by Kevin Pulo [ 02/Mar/16 ] | ||
|
$HOME is another variable that can be very useful to know the value of. The functions could possibly also be called getenv()/setenv() (but otherwise work roughly the same), since those are the underlying POSIX libc functions that the implementation would use. Also unsetenv() or Env.unset() to unset environment variables. And maybe clearenv() (which is not in POSIX). A more convenient interface might be a magic object whose fields represent the environment values. I'm pretty sure that a Proxy (now that we have ES6) could be used to implement this cleanly by hooking field get/set/delete and doing the necessary thing, ie. this could be a pure js convenience layer on top of lower-level (natively implemented) getenv()/setenv()/unsetenv(). | ||
| Comment by James M. Greene [ 10/Jul/15 ] | ||
|
I followed a similar pattern as @Justin's comment except that I passed in the environment variables by using an
It's a pretty solid workaround but I'd definitely rather that I didn't need to do so at all. | ||
| Comment by Justin [ 18/Mar/13 ] | ||
|
A work around I use: alias mongo="export | sed 's/declare -x /env./' > shell.js; mongo $@; rm shell.js;" In ~/mongorc.js: var env = {}; You can change shell.js to something more unique or add it to /tmp so you don't clobber something inadvertently. |