When I open the Cygwin64 Terminal then does /etc/bash.bashrc
run?
Short Answer:
Yes. I added some echo statements to the bash startup files and opened a Cywin64 Terminal. Here is the output:
/etc/bash.bashrc
/home/DavidPostill/.bash_profile
.profile
/home/DavidPostill/.bashrc
/home/DavidPostill/.bashrc
$
For some reason ~/.bashrc
is called twice, at the moment I'm not sure why.
Long Answer:
The shortcut for the Cygwin64 Terminal runs the following command:
C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -
The help for mintty
states:
$ mintty --help
Usage: mintty [OPTION]... [ PROGRAM [ARG]... | - ]
Start a new terminal session running the specified program or the user's shell.
If a dash is given instead of a program, invoke the shell as a login shell.
So we can see the the trailing -
on the shortcut command causes a login shell to be run.
What happens next depends on what your login shell is set to.
Assuming it set to bash
then:
If it is a login shell Cygwin will execute ~/.bash_profile
if it exists or otherwise ~/.profile
.
Note that .bash_profile
will execute ~/.profile
If it is an interactive shell Cygwin will execute ~/.bashrc
.profile (other names are also valid, see the bash man page) contains bash commands. It is executed when bash is started as login shell, e.g. from the command bash --login. This is a useful place to define and export environment variables and bash functions that will be used by bash and the programs invoked by bash. It is a good place to redefine PATH if needed. We recommend adding a ":." to the end of PATH to also search the current working directory (contrary to DOS, the local directory is not searched by default). Also to avoid delays you should either unset MAILCHECK or define MAILPATH to point to your existing mail inbox.
.bashrc is similar to .profile but is executed each time an interactive bash shell is launched. It serves to define elements that are not inherited through the environment, such as aliases. If you do not use login shells, you may want to put the contents of .profile as discussed above in this file instead.
Source Customizing bash
If you use
bash
from script when it called as#!/bin/bash
it is non interactive and bash won't pick up.bashrc
, but if you run bash as seating in console then it is interactive and.bashrc
loaded in this case – Alex – 2017-01-22T00:09:11.097@Alex So whether its interactive login or interactive non-login, the
.bashrc
is read? – ChumboChappati – 2017-01-22T00:24:04.533I will answer in "answer" to avoid restriction on maximum characters per comment – Alex – 2017-01-22T08:09:25.663