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
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.
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.
Source is specific for #!/bin/bash, so either you
substitute
#!/bin/sh
with
#!/bin/bash
substitute
source $dotfile
with
. $dotfile
ETA: as a matter of fact, the error complains that 'source' is not found, not its argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With