我的 Vagrantfile
中有以下代码调用以下脚本。该脚本运行良好,直到最后一行 source $dotfile
。当到达 source
时,脚本会显示 source: not found
。之前的行 cat $dotfile
工作正常,因此文件显然存在。
为什么这个文件以某种方式找不到 source
命令,但它适用于以前的 cat
命令?
输出错误
==> default: /vagrant/scripts/create_functions_dotfile.sh: 14: /vagrant/scripts/create_functions_dotfile.sh: source: not found
Vagrant 文件
config.vm.provision "#{script["name"]}", type: "shell" do |shell|
shell.inline = "/bin/sh /vagrant/scripts/create_functions_dotfile.sh"
end
scripts/create_functions_dotfile.sh
#!/bin/sh
dotfile=/home/vagrant/.functions.sh
for file in /vagrant/scripts/functions/*; do
echo "cat $file >> $dotfile"
cat $file >> $dotfile
done
echo "source $dotfile" >> /home/vagrant/.bashrc
cat $dotfile
source $dotfile
最佳答案
源代码特定于#!/bin/bash,所以要么你
替代
#!/bin/sh
与
#!/bin/bash
替代
source $dotfile
与
. $dotfile
ETA:事实上,错误提示找不到“源”,而不是它的参数。
关于bash - 在 Vagrant up 上找不到源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36031128/