Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.bashrc not used when bash.exe -c "echo $ENV" #24

Closed
jamespacileo opened this issue Apr 7, 2016 · 11 comments
Closed

.bashrc not used when bash.exe -c "echo $ENV" #24

jamespacileo opened this issue Apr 7, 2016 · 11 comments

Comments

@jamespacileo
Copy link

Hi,

sorry for raising this if it's how it is meant to be. Raising this just in case :)

I've added environment variables as a test in .bashrc.

Environment variables are set when opening bash.exe.
Environment variables are not set when passing a command to bash.exe.

Thanks

@crutchcorn
Copy link

This is because (IIRC), running bash.exe does nothing but start the init process for Ubuntu Userspace, it's not actually running bash. A better title would be something like "allow command line parameters through bash.exe", and is more of a feature than a bug

@patryk9200
Copy link

@crutchcorn It's not true, you are wrong.
Open cmd.exe and type:

bash -c "ls"
and next try:

bash -c "ls /"

@jamespacileo
Copy link
Author

@patryk9200 @crutchcorn yup, bash.exe -c '...' runs bash with commands/scripts within the folder it's called in.

bash -c "pwd"

There are some args which mention the bashrc file, e.g. --norc

Looking forward to know if someone figures this out 😄

@patryk9200
Copy link

@jamespacileo I found way to load .bashrc ;-)

Try something like these:

bash -c '. ~/.bashrc; bash -c "echo $YOUR_VARIABLE"'

That should work too:

bash -c 'source ~/.bashrc; bash -c "echo $YOUR_VARIABLE"'

@patryk9200
Copy link

You can make .bat file that will load variables and open bash for you:

echo bash -c "source ~/.bashrc; bash;" > test.bat

@jamespacileo
Copy link
Author

Snap! Thanks @patryk why didn't I think of this! Sweet and simple 😄👍
On Thu, 7 Apr 2016 at 17:35, Patryk [email protected] wrote:

You can make .bat file that will load variables for you:

echo bash -c "source ~/.bashrc; bash;" > test.bat


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#24 (comment)

@patryk9200
Copy link

@jamespacileo I think you can close issue right now ;-)

@patryk9200
Copy link

@jamespacileo @AlvaroOrduna
I just realized myself that

echo bash -c "source ~/.bashrc; bash;" > test.bat

is redundant.
Change this to:

echo bash -c "bash" > test.bat

Previous version loaded ~/.bashrc twice.

@jamespacileo
Copy link
Author

@patryk9200 ok this might a different issue in disguise then...

try the following

bash -c "echo $PATH"

It's not outputting anything. Are you getting the same?

I thought it was the ~/.bashrc not executing, but it might be something to do with env variables in general when running bash this way

@patryk9200
Copy link

@jamespacileo You are right that the ~/.bashrc is not executing.
When you run from cmd.exe:

bash -c "bash"

it will start bash inside bash but the second one bash is properly initialized. Bash initialized outside linux shell don't have sourced ~/.bashrc.
I think it's working this way because it's initialized from different user & different dir, so probably it's trying to load ~/.bashrc. from wrong path.

So it's why i removed source ~/.bashrc;, it was redundant.

You can add to ~/.bashrc:

echo TEST

Then if you run

bash -c "source ~/.bashrc; bash;"

You will get:

TEST
TEST

But if you remove source ~/.bashrc and run:

bash -c "bash"

You will get:

TEST

You can close it now.

@russalex
Copy link
Contributor

Closing based on the final comment.

Please feel free to re-open if this does not solve the OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants