Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source not found on Vagrant up

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
like image 682
Merlin -they-them- Avatar asked Mar 16 '16 09:03

Merlin -they-them-


People also ask

What is vagrant up command?

Command: vagrant up [name|id] This command creates and configures guest machines according to your Vagrantfile. This is the single most important command in Vagrant, since it is how any Vagrant machine is created. Anyone using Vagrant must use this command on a day-to-day basis.

Which vagrant command starts a vagrant virtual machine?

When you log into the virtual machine, by default it starts in the /home/vagrant/ directory. A different directory, /vagrant/, holds the same files that are on your host system. You can use vagrant up and vagrant ssh to launch and log into the virtual machine, then create a test document in the /vagrant directory.


1 Answers

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.

like image 54
Patrick Trentin Avatar answered Sep 19 '22 04:09

Patrick Trentin