6

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
Merlin -they-them-
  • 2,731
  • 3
  • 22
  • 39
  • WRT a suggested edit that changed code in an answer, [suggested reading](http://meta.stackoverflow.com/a/266479/1677912). – Mogsdad Mar 24 '16 at 20:03

1 Answers1

7

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.

Patrick Trentin
  • 7,126
  • 3
  • 23
  • 40