Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set PATH for Cygwin bash

I have script foo.sh in my Cygwin directory /usr/local/bin. I can run it using mintty, but not using bash.

When I started, the situation was as follows:

foo.sh in mintty   -   WORKING
foo.sh in bash     -   NOT WORKING

Then I added line export PATH="${PATH}:/usr/local/bin" to my .bashrc file. Now situation is as below:

foo.sh in mintty   -   WORKING
foo.sh in bash     -   WORKING
however
bash -c foo.sh     -   NOT WORKING

I need the last method of running the script to work. I will use it in my executable, which is compiled for Windows, so the command musts work in cmd.

My questions are:

  1. How to set variable PATH, to work with bash -c.
  2. Why /usr/local/bin is not in PATH by default? Is it any reason to don't do that I'm trying to do?
like image 474
NO_NAME Avatar asked Dec 06 '25 17:12

NO_NAME


1 Answers

The .bashrc file is only executed for non-login shells. For environments like this, I recommend including .bashrc from .bash_profile:

echo '. "${HOME}/.bashrc"' >> ~/.bash_profile

This way, your .bashrc will be included for both login and non-login shells.

like image 183
Will Avatar answered Dec 08 '25 08:12

Will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!