Create an alias in Vagrant shell provision

33 Views Asked by At

I can't figure out why my alias definition within the Vagrantfile shell provisioning script is not working.

This is (a part of) my Vagrantfile:

config.vm.provision "shell", inline: <<-SHELL
  # this works
  #echo 'alias pa="php artisan"' >> ~/.bash_aliases && source ~/.bash_aliases

  # this doesn't
  alias pa="php artisan"
  
  # in order to be able to do this
  pa migrate --seed
SHELL

If I SSH into the guest and create an alias w/ alias="command" i can use the command immediately. But doing the same from the shell script doesn't work.

What am I missing here?

1

There are 1 best solutions below

0
vasilli On

As noted by Fravadona, you can't use an alias in a non-interactive shell. But you can create a function. So, this solution works:

pa() { php artisan "$@"; }