Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between .bashrc and .bash _ profile in Linux

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what is the difference between .bashrc and .bash _ profile in Linux. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Interactive Login and Non-Login Shell

When Bash is called, it reads and executes commands from a set of startup files, depending on whether Shell is invoked as an interactive login call or as a non-login Shell.

In fact, Shell can be interactive or non-interactive. To put it simply, interactive Shell is a kind of Shell that reads and writes user terminals, while non-interactive Shell is a completely terminal-independent Shell. It is worth noting that the interactive Shell can be either a login Shell or a non-login Shell.

There are several situations where login Shell can be called, either when the user logs in remotely to the terminal via ssh or locally, or when the-- login option is used to launch Bash. For example, when you type bash at the Shell prompt or open a new Gnome terminal tab. The interactive non-login Shell is called from the login Shell.

Bash startup file

When Bash is called as an interactive login Shell, it looks for the / etc/profile file and, if it exists, it runs the commands listed in the file. Bash then searches for ~ / .bash_profile, ~ / .bash_login, and ~ / .profile files in the following order and executes the command in the first file found.

Differences between .bashrc and .bash _ configuration files

When Bash is called as an interactive login Shell, the .bash_profile is read and executed, while .bashrc is executed when the interactive non-login Shell is started. You typically use .bash _ profile to run commands that run only once, such as commands that run the custom environment variable PATH.

Each time you start a new Shell, you should put the commands you run in a .bashrc file, including aliases and functions, custom prompts, history customization, and so on.

Usually, ~ / .bash_profile contains commands from .bashrc files, as shown in the following example:

This means that each time you log in to the terminal, the above two files are read and the commands in them are executed.

Most Linux distributions use ~ / .profile instead of ~ / .bash_profile. Because ~ / .profile files can be read by all Shell, while ~ / .bash _ profile can only be read by Bash Shell.

If you don't have the startup files I mentioned above on your system, you can also create them yourself.

These are all the contents of this article entitled "what's the difference between .bashrc and .bash _ profile in Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report