在 Vagrant up 上找不到源

Source not found on Vagrant up

我的 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

来源特定于 #!/bin/bash,因此您

  1. 替代

    #!/bin/sh 
    

    #!/bin/bash 
    
  2. 替代

    source $dotfile
    

    . $dotfile
    

ETA:事实上,错误抱怨找不到 'source',而不是它的参数。