自动更改目录到时无业游民目录"无业游民SSH" [英] Automatically chdir to vagrant directory upon "vagrant ssh"

查看:124
本文介绍了自动更改目录到时无业游民目录"无业游民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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆