在Vagrant上找不到来源

时间:2016-03-16 09:10:32

标签: bash shell vagrant sh file-not-found

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

1 个答案:

答案 0 :(得分:5)

来源特定于#!/ bin / bash,所以你要么

  1. 替换

    #!/bin/sh 
    

    #!/bin/bash 
    
  2. 替换

    source $dotfile
    

    . $dotfile
    
  3. ETA:事实上,错误抱怨找不到“来源”,而不是其论点。

相关问题