自动更改目录到时无业游民目录"无业游民SSH" [英] Automatically chdir to vagrant directory upon "vagrant ssh"
问题描述
所以,我已经得到了运行Linux的一番风味(CentOS的,Ubuntu的,等等)一帮无业游民的虚拟机。我想自动确保一个无业游民SSH也将CD /无业游民,因此,没有人必须记住要做到这一点,每当他们登录。
So, I've got a bunch of vagrant VMs running some flavor of Linux (centos, ubuntu, whatever). I would like to automatically ensure that a "vagrant ssh" will also "cd /vagrant" so that no-one has to remember to do that whenever they log in.
我已经想通了(废话!)那回声\\ n \\ NCD /游民>> /home/vagrant/.bashrc
会做的伎俩。我不知道的是如何确保在cd命令已不存在这只是发生。我不是一个shell专家,所以我完全糊涂了这里。 :)
I've figured out (duh!) that echo "\n\ncd /vagrant" >> /home/vagrant/.bashrc
will do the trick. What I don't know is how to ensure that this only happens if the cd command isn't already there. I'm not a shell expert, so I'm completely confused here. :)
推荐答案
CD
是一个bash shell内置,只要安装一个外壳应该还有
cd
is a Bash shell built-in, as long as a shell is installed it should be there.
此外,要知道,〜/ .bash_profile中
是交互式登录shell,如果您添加 CD /游民
在〜流浪汉/ .bashrc中
,它可能无法正常工作。
Also, be aware that ~/.bash_profile
is for interactive login shell, if you add cd /vagrant
in ~vagrant/.bashrc
, it may NOT work.
由于如Ubuntu发行版没有这个文件 - > 〜/ .bash_profile中
默认情况下,而使用〜/ .bashrc中
和〜/ .profile文件
Because distros like Ubuntu does NOT have this file -> ~/.bash_profile
by default and instead use ~/.bashrc
and ~/.profile
如果有人创建一个〜/ .bash_profile中
为Ubuntu的用户漂泊不定,〜流浪汉/ .bashrc中
不会被读出。
If someone creates a ~/.bash_profile
for vagrant user on Ubuntu, ~vagrant/.bashrc
will not be read.
这篇关于自动更改目录到时无业游民目录"无业游民SSH"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!