为什么 `source /home/vagrant/.bashrc` 在 Vagrant shell 配置脚本中不起作用?
Why is `source /home/vagrant/.bashrc` not working in a Vagrant shell provisioning script?
我 使用 Vagrant 使用的 shell 配置脚本,因为它没有执行 source /home/vagrant/.bashrc
。我已将问题简化为...
在我的 VM 中,我在 /home/vagrant/testfile
有一个文件,其中包含:
echo "In testfile"
在 /home/vagrant/.bashrc
的结尾,我有这个:
echo "In .bashrc"
这两个文件都属于 vagrant
用户。
在我的一个 Vagrant 配置 shell 脚本中,我有这个:
echo "Hello"
source /home/vagrant/testfile
source /home/vagrant/.bashrc
echo "Goodbye"
运行 vagrant provision
给出:
Hello
In testfile
Goodbye
当我执行 vagrant ssh
时,/home/vagrant/.bashrc
和往常一样是 运行,我会自动看到:
In .bashrc
那么为什么 source /home/vagrant/.bashrc
在我的配置脚本中没有效果?
您需要从 .bashrc
.
顶部删除“如果不是 运行 交互式退出”位(例如 [ -z "$PS1" ] && return
)
我 source /home/vagrant/.bashrc
。我已将问题简化为...
在我的 VM 中,我在 /home/vagrant/testfile
有一个文件,其中包含:
echo "In testfile"
在 /home/vagrant/.bashrc
的结尾,我有这个:
echo "In .bashrc"
这两个文件都属于 vagrant
用户。
在我的一个 Vagrant 配置 shell 脚本中,我有这个:
echo "Hello"
source /home/vagrant/testfile
source /home/vagrant/.bashrc
echo "Goodbye"
运行 vagrant provision
给出:
Hello
In testfile
Goodbye
当我执行 vagrant ssh
时,/home/vagrant/.bashrc
和往常一样是 运行,我会自动看到:
In .bashrc
那么为什么 source /home/vagrant/.bashrc
在我的配置脚本中没有效果?
您需要从 .bashrc
.
[ -z "$PS1" ] && return
)