0

I have a Powershell profile set up with this alias:

New-Alias dev C:\websites\dev\bin\dev.sh -Scope Global

from the Powershell this works fine. dev.sh is actually a binary (the .sh will come off, on for other reasons) that sets some env variables and runs commands.

I have a shell script that looks like this:

#!/bin/sh

dev rebuild

dev exec identity php artisan migrate:fresh
dev exec identity php artisan db:seed --class=DemoSeeder

dev exec matching php artisan migrate:fresh --seed
dev exec matching php artisan db:seed --class=DemoSeeder

This fails with bash: dev: command not found

I don't think this is any sort of exporting alias problem, since it works fine from the Powershell cli, but rather that the shell script can't read the alias. Possible solutions seem to prefer that I modify a .bashrc to set the alias, or to try to set it inside the script itself, but I don't think either of these will be very good to work across a team with different operating systems & repo locations

How can I get the .sh script to read the dev alias?

jmadsen
  • 3,635
  • 2
  • 33
  • 49
  • This is an alias export issue actually. Your script will create a new subshell, that will not inherit the parent aliases. You'll need to source / create the alias in your shell script – Aserre Nov 29 '21 at 07:18
  • Cross site duplicate : https://superuser.com/questions/319538/aliases-in-subshell-child-process – Aserre Nov 29 '21 at 07:20
  • @jmadsen : While I have never worked with _powershell_, I'm pretty sure that you have to actually invoke powershell, if you need a command to be executed by it. Also, what's the point in creating a **powershell** alias, if you want to run it from bash (or sh)? C:\websites\dev\bin isn't even a valid pathname in bash. – user1934428 Nov 29 '21 at 12:31
  • because I don't always want to run it from bash; usually it runs from Powershell – jmadsen Nov 29 '21 at 20:49

1 Answers1

0

After a bit more reading & learning, the answer is:

Shell scripts have their own scope with regards to aliases (a sysops person might say that differently, but I think that explains it clearly to the person who is looking for this answer). Therefore, you do need to use the .bashrc to set up your alias

Here is a helpful answer that explains that better for Windows: Git for Windows: .bashrc or equivalent configuration files for Git Bash shell

jmadsen
  • 3,635
  • 2
  • 33
  • 49