Home > System Tutorial > Linux > body text

Do you know the difference between interactive shell and profile?

WBOY
Release: 2024-02-14 16:09:02
forward
701 people have browsed it

Reprinted from:/u010127245/article/details/51689636

The difference between bashrc and profile

The difference between bashrc and profile, we must first understand which are interactive shells and non-interactive shells, and which are login shells and non-login shells.

Interactive mode means that the shell waits for your input, but executes the commands you submit. These modes are called interactive because the shell interacts with the user. These modes are also familiar to most users: logging in, executing some commands, and logging out. When you sign back, the shell also terminates.

The shell can also run in another mode: non-interactive mode. In these modes, the shell does not interact with Android Linux, but reads commands stored in files, but executes them. When it reaches the end of the file, the shell terminates.

Bashrc and profile are both used to save the user's environment information, bashrc is used for interactive non-login shellLinux installation cross-compilation environment variables, and profile is used for interactive login shell. There are many bashrc and profile files in the system. They are introduced one by one below:

/etc/pro This file sets environment information for each user of the system. When the first user logs in, this file is executed.

And collect shell settings from the configuration file in the /etc/profile.d directory.

/etc/bashrc: Execute this file for each user running bashshell. When bashshell is opened, this file is read. There is no bashrc file in the /etc directory in some Linux versions.

~/.pro Each user can use this file to enter shell information specifically for their own use. When the user logs in, the

The file is only executed once! By default, it sets some environment variables and then executes the user's .bashrc file.

~/.bashrc: This file contains bash information specific to a user's bash shell. This file is read when the user logs in and every time a new shell is opened.

In addition, the variables (global) set in /etc/profile can affect any user, while the variables (local) set in ~/.bashrc, etc. can only inherit the variables in /etc/profile. They It's a "brother and sister" relationship.

Summarize:

交叉编译环境变量如何设置_交叉编译环境搭建步骤_linux安装交叉编译环境变量

/etc/profile, /etc/bashrc is the system global environment variable setting

~/.profile, ~/.bashrc private environment variable settings in the user’s home directory

When a shell process is obtained when logging into the system, there are three steps to read the environment configuration file

1 The first thing to read is the global environment variable configuration file /etc/profile, and then read additional setting documents according to its content, such as

/etc/profile.d and /etc/inputrc

2 Afterwards, according to different user accounts, go to their home directory to read ~/.bash_profile. If this cannot be read, read ~/.bash_login. If this cannot be read, then read it

linux安装交叉编译环境变量_交叉编译环境搭建步骤_交叉编译环境变量如何设置

~/.profile, the settings of these three documents are basically the same, and reading has priority

3 Afterwards, read ~/.bashrc

according to the user account

As for the difference between ~/.profile and ~/.bashrc

All have personalized customization functions

~/.profile can set the user's own path to install win7 on the Linux system, environment variables, etc. It can only be executed once when logging in

~/.bashrc is also a user-specific setting document. You can set the path and command alias. It will be used once every time shellscript is executed.

[Three ways to configure environment variables]

If you want to add a path to $PATH, you can do the following:

1. Console North does not agree with the use of these techniques. Because if you change the shellLinux installation cross-compilation environment variables, your settings will be invalid, so these methods are only for temporary use and will be used later. You have to reset it again, which is quite troublesome. This is only for a specific shell;

$PATH="$PATH:/my_new_path" (turn off the shell and PATH will be restored)

2.

Change the /etc/profile file. If your computer is only used for development, it is recommended to use these techniques. Since all user shells have the right to use this environment variable, it may bring security issues to the system. (JDK configuration recommended)

This is for all users and all shells;

$vi/etc/profile add:

exportPATH="$PATH:/my_new_path"

3.

Change the .bashrc file. These techniques are safer. It can control the permission to use this environment variable to the user level. This is for a specific user. If you need to give a user permission to use this environment Variables, you only need to change the .bashrc file in the home directory for personal use.

$vi/root/.bashrcAdd above:

exportPATH="$PATH:/my_new_path"

The latter two methods usually require logging out of the system again to take effect (you can directly use $source~/.profile refresh to prevent restarting). Finally, you can test it through the echo command:

$echo$PATH output is already the new path.

The above is the detailed content of Do you know the difference between interactive shell and profile?. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!