bash - 在 Vagrant up 上找不到源

标签 bash shell vagrant sh file-not-found

我的 Vagrantfile 中有以下代码调用以下脚本。该脚本运行良好,直到最后一行 source $dotfile。当到达 source 时,脚本会显示 source: not found。之前的行 cat $dotfile 工作正常,因此文件显然存在。

为什么这个文件以某种方式找不到 source 命令,但它适用于以前的 cat 命令?

输出错误

==> default: /vagrant/scripts/create_functions_dotfile.sh: 14: /vagrant/scripts/create_functions_dotfile.sh: source: not found

Vagrant 文件

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:事实上,错误提示找不到“源”,而不是它的参数。

关于bash - 在 Vagrant up 上找不到源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36031128/

相关文章:

python - 如何像 pip 一样卡住 brew 需求?

ruby - 共享文件夹前的 Vagrant 预配置

linux - 在 RAM 中运行 Vagrant VM 有哪些方法?

bash - 如何使用 Bash 遍历日期?

linux - bash 重定向到/dev/stdout : Not a directory

bash - ubuntu服务器用点重命名文件

linux - 脚本从上次运行中获取参数

bash - shell脚本中的while循环条件

json - 使用 jq 就地修改 json 中的键值

chef-infra - Vagrant 配置因关闭流而失败 (IOError)