Vagrant up时找不到源代码

6
我在我的中有以下代码,它调用下面的脚本。该脚本一直运行良好,直到最后一行。当到达时,脚本会显示。前面的这一行工作得非常好,因此该文件明显存在。为什么这个文件对于命令来说找不到,但是对于先前的命令却可以正常工作呢? <输出错误>
==> 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

关于建议修改答案中代码的问题,建议阅读 - Mogsdad
1个回答

7

Source是特定于#!/bin/bash的,因此您

请提供更多需要翻译的内容。
  1. substitute

    #!/bin/sh 
    

    with

    #!/bin/bash 
    
  2. substitute

    source $dotfile
    

    with

    . $dotfile
    
ETA:事实上,错误提示是“未找到源”,而不是其参数。

解决了。谢谢。我使用sh是因为我曾经读过sh更具可移植性,且会自动指向bash - Merlin -they-them-

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接