Reputation: 2418
I am trying to get a bash script to run in git bash while specifying a different .bashrc than the one in my home directory (or none at all) however it is proving an impossible task.
To my understanding this should work:
"C:\Program Files (x86)\Git\bin\sh.exe " --rcfile .bashrc --login -i C:/Scripts/myscript.sh
However no matter what I try either the --rcfile file flag will be completely ignored or the script will get parse errors because it is not parsed by bash.
The following are my findings:
I have tried every possible combination I think of, including calling the script within my .bashrc file, swapping the flags around, using the -c flag to run the script command and swapping my .bashrc files around to try using the --norc flag instead.
Is this just a result of shitty bash implementation for windows or am I doing something wrong?
Any help on the matter is appreciated.
Upvotes: 4
Views: 6121
Reputation: 531165
As far as I can tell, the -i
flag is overridden by the fact that you provide a script for bash
to run. Your shell isn't actually interactive, so --rcfile
is ignored. The only way I can tell to both run a script and source an additional file is to use a non-interactive login shell; however, in that case, you are restricted to using .bash_profile
, .bash_login
, or .profile
, whichever is found first:
bash --login myscript.sh
There is no --loginfile
to override the choice of file sourced prior to myscript.sh
.
UPDATE: I forgot about BASH_ENV
.
export BASH_ENV=.bashrc
bash myscript.sh
I do not know how you would go about adding BASH_ENV
to your environment in Git bash.
Upvotes: 1
Reputation: 20456
You can try sourcing your .bashrc
inside the script myscript.sh
.
source .bashrc
Or
. .bashrc
Upvotes: 2