我的Vagrantfile
中有以下代码,它调用以下脚本。脚本运行正常,直到最后一行source $dotfile
。当它到达source
时,脚本会显示source: not found
。之前的行,cat $dotfile
工作正常,因此文件显然存在。
为什么source
命令找不到此文件,但它适用于以前的cat
命令?
output error
==> default: /vagrant/scripts/create_functions_dotfile.sh: 14: /vagrant/scripts/create_functions_dotfile.sh: source: not found
Vagrantfile
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
答案 0 :(得分:5)
来源特定于#!/ bin / bash,所以你要么
替换
#!/bin/sh
带
#!/bin/bash
替换
source $dotfile
带
. $dotfile
ETA:事实上,错误抱怨找不到“来源”,而不是其论点。