linux profile vs .bashrc

/etc/profile: This file sets the environment information for each user of the system. When the user logs in for the first time, this file is executed.
And collect the shell settings from the configuration file in the /etc/profile.d directory.
/etc /bashrc: Execute this file for each user running the bash shell. When the bash shell is opened, this file is read.
~/.bash_profile: Each user can use this file to enter specific shell information for their own use, When the user logs in, this
file is executed only once! By default, he sets some environment variables and executes the user's .bashrc file.
~/.bashrc: This file contains bash information specific to your bash shell, when logging in and
This file is read every time a new shell is opened .
~/.bash_logout: This file is executed each time the system is exited (exit the bash shell). 

In addition, the variables set in /etc/profile (global) can act on any user, and the variables (local) set in ~/.bashrc can only inherit the variables in /etc/profile, they are a "parent-child" relationship.
 
~/.bash_profile is an interactive, login method to enter The
~/.bashrc run by bash is an interactive non-login way to enter the bash run.
Usually the two settings are roughly the same, so the former usually calls the latter.

The setting takes effect: it can be restarted to take effect, or you can use the command: source
alias php=/var/eyouim/pub/php/bin/php
source /etc/profile

2.3. User Environment Configuration

To make Bash work better for us, we need to customize the bash shell environment.

2.3.1. .bash_profile、.bashrc、和.bash_logout

  1. The above three files are the user environment configuration files of the bash shell, located in the user's home directory. Among them, .bash_profile is the most important configuration file. It is read every time the user logs in to the system, and all commands in it will be executed by bash. The two files .profile (used by the Bourne Shell and Korn Shell) and .login (used by the C Shell) are synonyms for .bash_profile for compatibility with other shells. Use .profile file instead of .bash_profile file in Debian.

  2. The .bashrc file is read when the bash shell invokes another bash shell, that is, the file is read when a bash command is typed in the shell to start a new shell. This effectively separates the environments needed for login and subshells. But generally speaking, the .bashrc script is called in .bash_profile to uniformly configure the user environment.

  3. .bash_logout is read when exiting the shell. So we can put some cleanup commands into this file.

The bash.bashrc and profile in the /etc directory are system-level (global) configuration files. When .bash_profile and .bashrc\ are not found in the user's home directory, these two files will be read. .bash_history is the history file of the bash shell, which records all the commands you enter in the bash shell. The number of records saved in the history file can be set through the HISSIZE environment variable. alias l = 'ls -l' is the statement to set the alias, putting it in these configuration files allows us to use the simple 'l' command instead of the 'ls -l' command.

 
[Note]
When we modify these configuration pieces, we can use the source .bash_profile command to make the modifications take effect immediately.

2.3.2. Options

Options in the bash shell control the behavior and functionality of the shell, which we can set through the shopt command. It is also possible to use the set command, but it has been replaced by shopt, but for backward compatibility, the set command can still be used. Use the shopt command without parameters to list options that can only be set by shopt in the current shell, and use shopt -o to list options that can be set by the set command.

Below are some basic options available by the set command, which are disabled by default.

emacs Enter emacs editing mode
vi Enter vi editing mode
ignoreeof does not allow the use of Ctrl_D to exit alone, use exit. Equivalent to IGNOREEOF=10
noclobber does not allow redirection to overwrite existing files
noglob does not allow expanded filename wildcards
nounset gives error when using undefined variable

Below are some options that can only be set by the shopt command.

cdspell automatically corrects minor errors in cd command arguments
When hostcomplete starts with @, press the tab key to automatically complete the host name
dotgblob filenames starting with a dot are included in the pathname extension
mailwarn displays mail warning messages

The options for the shopt command are as follows:

-p Display settable options and current values
-s sets each option to on
-u sets each option to off
-q do not output information
-O          

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327053935&siteId=291194637