我的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的,所以您要么

  • 替代
    #!/bin/sh
    


    #!/bin/bash
    
  • 替代
    source $dotfile
    


    . $dotfile
    


  • ETA:事实上,该错误提示找不到“源”,而不是其参数。

    10-08 13:15