On the bash shell type and linux system profile and bashrc configuration file

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/LEON1741/article/details/100120749

I believe many people played linux, seeing as ~ / .bash_profile, ~ / .bashrc, ~ / .profile, / etc / profile, / etc / bashrc such documents, will have a feeling of deja vu, vaguely remember Configuration What time parameters or path used these files, or to modify system settings when they turn over. There is also a little bad, in fact, can point out that these documents can be divided into two categories, namely bashrc and profile, they are used to configure the environment variables, when a number of development tools when you install must modify these files to make installation the content can take effect globally. However, if you want to analyze in detail the profile and bashrc exactly what stuff, above the respective roles of these documents, their differences, whether they can explain it clearly? Do not worry, here we come to a detailed expansion.

First, the type of shell

To completely clear the meaning and role of these documents above, we must first understand what is interactive shell (interactive shell) and non-interactive shell (non-interactive shell), what is the login shell (login type shell) and non- login shell (a non-signed formula shell).

  • interactive shell (interactive shell) shell is waiting for your input, and execute commands you submit. This mode is called an interactive because the shell interacts with the user. This model is also very familiar with most users: login, execute commands, sign-off. When you sign back, shell have terminated.

  • In addition to the interactive mode, shell can also run in another mode: non-interactive shell (non-interactive shell). In this mode, shell do not interact with you, but read commands stored in a file and execute them. When the end of the file it read, shell will cease.

  • login shell (login type shell) refers to the need to complete at the time of acquisition bash login process. When did you get bash? Of course, it is when the user logs in. When you log in tty1 ~ tty6, the system will ask you to enter the account number and password, bash acquired at the time is a kind of login shell.

  • non-login shell (non-login shell type) is to get bash to log need not be repeated, just as you view the desktop using ctrl + alt + T to start the shell input window is non-login shell. There is a user in a shell window you switch directly su, are all non-login shell.

These two classifications are crossed, that is to say a login shell may be an interactive shell, it may be a non-interactive shell.

interactive shell (interactive shell) and non-interactive shell (non-interactive shell) is actually very good understanding, there is nothing more than an explicit interface. More difficult to understand the login shell (sign Formula shell) and non-login shell (a non-signed formula shell). According to the online summary of the cattle, login shell and the main difference is that non-login shell reads different configuration files when they are activated, resulting in their working environment is different.

  • When the login shell starts first read / etc / profile global configuration, lookup followed /.bash_profile, /.bash_login,~/.profile three profiles, finds and reads the first and readable file. login shell reads and executes ~ / .bash_logout commands exit.

  • When you start reading the Login shell-interactive non /.bashrc resource file. If we modify our /.bashrc If you want a profile take effect immediately, we just use the source command. For example: $ source ~ / .bashrc;

  • Noninteractive all the above non-login shell configuration file is not read, but find BASH_ENV environment variables, file read and execute the command pointed BASH_ENV;

As a comparison, it should detail is more clear.

Two, bashrc file with profile

Here we talk about the profile bashrc file. bashrc and profile are used to store information about the user's environment:

  • bashrc for interactive non-login shell;

  • profile for interactive login shell;

As described above, the system will generally present a plurality of profile and bashrc file, following elaborate:

  • [File / etc / profile]: Set the environment information for each user of the system. When the system first user logs, the file is executed;

  • [File / etc / bashrc]: to set the environment information for each user running the bash shell. When bash shell is opened, the file is executed;

  • [File ~ / .profile]: Each user can use the file input information specific to shell their own use, the file only once, in the future will no longer execute when the user logs in, and then log back in until you log out after . By default, it sets some environment variables, and then execute .bashrc file users;

  • [File ~ / .bashrc]: dedicated to a user contains information about the bash shell bash, when the user logs on, and each time a new shell is opened, the file is read;

Further action can, / etc / profile set any user variable, global variable, and the variable set in ~ / .bashrc can inherit the like / etc / profile variables, local variables, they are "parent-child" relationship;

The same can be explained:

  • [File / etc / profile [] and / etc / bashrc] for setting a system global environment variables;
  • File [ /.profile] and [ /.bashrc] for setting a private single user environment variables;

When logged time to get a shell process, which reads the environmental profile has three steps:

  1. First reads the global environment profile [/ etc / profile], and then reads the additional set of documents based on their content, such as
    [] and [/etc/profile.d / etc / inputrc];
  2. Then according to different user accounts, read to their HOME directory [ /.bash_profile], the file can not be read if you read [ /.bash_login], this can not be read will read [~ / .profile] this three document set is substantially the same, but when the read has priority relationship;
  3. Finally, according to a user account in the reading {~ / .bashrc];

Guess you like

Origin blog.csdn.net/LEON1741/article/details/100120749