bash 使用 Vagrant 从配置 shell 脚本更新 .bashrc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27026015/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:49:27  来源:igfitidea点击:

Update .bashrc from provisioning shell script with Vagrant

linuxbashvagrant

提问by Grant Trevor

I'm trying to add some additional lines to .bashrc in my home directory from the provisioning shell script when launching a new instance with Vagrant.

当使用 Vagrant 启动新实例时,我试图从配置 shell 脚本中向我的主目录中的 .bashrc 添加一些额外的行。

In the shell script I have:

在shell脚本中,我有:

set -x

sudo apt-get update

sudo apt-get install vim

echo "source /usr/local/share/chruby/chruby.sh">> ~/.bashrc
echo "source /usr/local/share/chruby/auto.sh">> ~/.bashrc

However after completion nothing has been written to .bashrc.

但是,完成后没有任何内容写入 .bashrc。

This is a cut down version of the full script the intention of which is to install Ruby/Rails.

这是完整脚本的简化版本,其目的是安装 Ruby/Rails。

回答by Sirrah

You need to give the full path to the file.

您需要提供文件的完整路径。

E.g.

例如

echo "source /usr/local/share/chruby/chruby.sh" >> /home/vagrant/.bashrc

回答by ShellFish

Add these lines to .bashrc

将这些行添加到 .bashrc

if [ -f /usr/local/share/chruby/chruby.sh ]; then
    . /usr/local/share/chruby/chruby.sh
fi

It will textually include the script into .bashrc and execute it when opening a new shell.

它将以文本形式将脚本包含到 .bashrc 中,并在打开新 shell 时执行它。

回答by philbrooksjazz

Try this for your last 2 lines - it should give you exactly what you need.

在最后 2 行中试试这个 - 它应该给你你所需要的。

echo "source /usr/local/share/chruby/chruby.sh" >> /home/vagrant/.bashrc

echo "source /usr/local/share/chruby/auto.sh" >> /home/vagrant/.bashrc