Abstract: I'm trying to explain the process of bash setup in this article.
Keywords:bash, shell, environment
It is usually hard to answer the question where this variable is set, because there is SO many different files involved. So let's start with some concepts:
- interactive login shell
- The shell started after a successful login, using /bin/login, by reading the /etc/passwd file.
- interactive non-login shell
- It is normally started at the command-line using a shell program (eg.
$/bin/bash
) or by the/bin/su
command. It is also started with a terminal program within a graphical environment. - non-interactive shell
- It's usually used to execute a shell script
An interactive login shell generally initializes with the following configuration files:
/etc/profile -> [~/.bash_profile] -> [~/.bash_login] -> [~/.profile]
In some systems, the /etc/profile
script will look for additional settings in /etc/profile.d/*.sh
, and the ~/.bash_profile
usually sources ~/.bashrc
.
When an interactive non-login shell starts, it first copies the environment of its parent shell and then reads its settings in the following order:
/etc/bash.bashrc -> [~/.bashrc]
Remember that only exported variables of its parent shell is copied, functions and aliases of its parent are NOT inherited.
A non-interactive shell simply copies environment from its parent, and does not read any configuration files.
No comments:
Post a Comment