且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

来源流浪了找不到

更新时间:2023-11-15 23:19:22

来源是具体的#!/斌/ bash的,所以要么你


  1. 替代

     #!/ bin / sh的

     #!/斌/庆典


  2. 替代

     来源$ dotfile

     。 $ dotfile



ETA:作为事实上,错误抱怨说,源是找不到的,不是它的参数

I have the below code in my Vagrantfile which calls the below script. The script runs fine up until the last line source $dotfile. When it gets to source, the script says source: not found. The line before, cat $dotfile works just fine so the file clearly exists.

Why is this file somehow not found for the source command but it works for the previous cat command?

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

Source is specific for #!/bin/bash, so either you

  1. substitute

    #!/bin/sh 
    

    with

    #!/bin/bash 
    

  2. substitute

    source $dotfile
    

    with

    . $dotfile
    


ETA: as a matter of fact, the error complains that 'source' is not found, not its argument.