gpt4 book ai didi

bash - 在 Vagrant up 上找不到源

转载 作者:行者123 更新时间:2023-11-29 09:04:31 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com