How to set PATH for Cygwin bash

7.1k Views Asked by At

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?
1

There are 1 best solutions below

0
On

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.