bash .bashrc 在 ssh 登录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/820517/
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
.bashrc at ssh login
提问by Hobhouse
When I ssh into my ubuntu-box running Hardy 8.04, the environment variables in my .bashrc
are not set.
当我通过 ssh 进入运行 Hardy 8.04 的 ubuntu-box 时,我的环境变量.bashrc
没有设置。
If I do a source .bashrc
, the variables are properly set, and all is well.
如果我做一个 source .bashrc
,变量设置正确,一切都很好。
How come .bashrc
isn't run at login?
为什么.bashrc
在登录时不运行?
回答by Ayman Hourieh
.bashrc
is not sourced when you log in using SSH. You need to source it in your .bash_profile
like this:
.bashrc
当您使用 SSH 登录时,不是来源。你需要.bash_profile
像这样获取它:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
回答by ruseel
I had similar situation like Hobhouse. I wanted to use command
我有类似霍布豪斯的情况。我想使用命令
ssh myhost.com 'some_command'
and 'some_command' exists in '/var/some_location' so I tried to append '/var/some_location' in PATH environment by editing '$HOME/.bashrc'
并且“some_command”存在于“/var/some_location”中,因此我尝试通过编辑“$HOME/.bashrc”在 PATH 环境中附加“/var/some_location”
but that wasn't working. because default .bashrc(Ubuntu 10.4 LTS) prevent from sourcing by code like below
但这不起作用。因为默认的 .bashrc(Ubuntu 10.4 LTS) 阻止通过如下代码进行采购
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
so If you want to change environment for ssh non-login shell. you should add code above that line.
所以如果你想改变 ssh 非登录 shell 的环境。您应该在该行上方添加代码。
回答by lhunath
回答by Lo?c Wolff
If ayman's solution doesn't work, try naming your file .profile
instead of .bash_profile
. That worked for me.
如果 ayman 的解决方案不起作用,请尝试将文件命名.profile
为.bash_profile
. 那对我有用。