bash 在 mac 上等价于 setenv?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18989111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
setenv equivalent on mac?
提问by user1871869
I want to set an environment variable using setenv:
我想使用 setenv 设置一个环境变量:
setenv NODE_ENV localhost
But setenv gives me an error saying the command is not found. Does anyone know how to perform the MAC OSX equivalent of setenv? Thanks!
但是 setenv 给了我一个错误,说找不到命令。有谁知道如何执行与 setenv 等效的 MAC OSX?谢谢!
回答by Doon
you want export
你要 export
NODE_ENV=localhost
export NODE_ENV
or on 1 line export NODE_ENV=localhost
或在 1 行 export NODE_ENV=localhost
and this has nothing to do with OSX per se, more to do with bash vs (t)csh as your shell
这与 OSX本身无关,更多的是与 bash vs (t)csh 作为你的 shell
回答by German
Best for Mac is:
最适合 Mac 的是:
launchctl setenv NODE_ENV localhost
if you want to make the variable persistent and avoid rebooting.
如果要使变量持久化并避免重新启动。
See:
看:
回答by David W.
Are you a Cshell person?
你是Cshell人吗?
The earlier versions of OS X came with tcsh
as the default shell since OS X is based upon BSD. However, Mac OS X comes with BASH as the user's default shell.
tcsh
由于 OS X 基于 BSD ,早期版本的 OS X作为默认 shell 提供。但是,Mac OS X 带有 BASH 作为用户的默认 shell。
Macs still come with Turbo Csh too and you can make this your default shell if that is your desire. In the terminal, type:
Mac 仍然带有 Turbo Csh,如果您愿意,可以将其设为默认 shell。在终端中,输入:
$ chsh -s /bin/tcsh
If you decide you want switch back to BASH:
如果您决定要切换回 BASH:
$ chsh -s /bin/bash
You can see a list of all possible shells in the /etc/shell
file.
您可以在/etc/shell
文件中看到所有可能的 shell 的列表。