问题描述
我遇到问题 shell 配置Vagrant 使用的脚本,因为它没有执行 source/home/vagrant/.bashrc
.我已将问题简化为这个...
I'm having problems with a shell provisioning script used by Vagrant, as it's not executing source /home/vagrant/.bashrc
. I've reduced the problem down to this...
在我的 VM 中,我在 /home/vagrant/testfile
中有一个文件,其中包含以下内容:
Within my VM I have a file at /home/vagrant/testfile
that contains this:
echo "In testfile"
在 /home/vagrant/.bashrc
的末尾我有这个:
And at the end of /home/vagrant/.bashrc
I have this:
echo "In .bashrc"
这两个文件都归 vagrant
用户所有.
Both files are owned by the vagrant
user.
在我的一个 Vagrant 配置 shell 脚本中,我有这个:
In one of my Vagrant provisioning shell scripts I have this:
echo "Hello"
source /home/vagrant/testfile
source /home/vagrant/.bashrc
echo "Goodbye"
运行 vagrant provision
给出:
Hello
In testfile
Goodbye
当我执行 vagrant ssh
然后 /home/vagrant/.bashrc
像往常一样运行,我自动看到:
When I do vagrant ssh
then /home/vagrant/.bashrc
is run as usual, and I automatically see:
In .bashrc
那么为什么在我的配置脚本中执行 source/home/vagrant/.bashrc
没有影响?
So why does doing source /home/vagrant/.bashrc
have no effect from within my provisioning script?
推荐答案
您需要删除如果不以交互方式运行则退出"位(例如 [ -z "$PS1" ] && return
) 从你的 .bashrc
顶部.
You need to remove the "exit if not running interactively" bit (e.g. [ -z "$PS1" ] && return
) from the top of your .bashrc
.
这篇关于为什么`source/home/vagrant/.bashrc` 在 Vagrant shell 配置脚本中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!