How to configure Bash environment variables in Linux

How to configure Bash environment variables in Linux

Shell is a program written in C language, which is a bridge for users to use Linux. Shell is both a command language and a programming language.

There are several shell versions, bash is the default:

sh (full name Bourne Shell): It is the shell originally used by UNIX and can be used on every UNIX.
The Bourne Shell is quite good at shell programming, but it does not do as well as other shells in handling interaction with users.
bash (full name Bourne Again Shell): The default for LinuxOS, it is an extension of Bourne Shell.
It is fully compatible with Bourne Shell and adds many features based on Bourne Shell. It can provide functions such as command completion, command editing and command history. It also contains many advantages of C Shell and Korn Shell, with a flexible and powerful editing interface and a very friendly user interface.
csh (full name C Shell): is a variant of Shell that is more suitable than Bourne Shell. Its syntax is very similar to C language.
Tcsh: is an extended version of C Shell provided by Linux.
Tcsh includes command line editing, programmable word completion, spelling correction, history command substitution, job control and C-like syntax. It is not only compatible with the Bash Shell prompt, but also provides more prompt parameters than the Bash Shell.
ksh (full name Korn Shell): combines the advantages of C Shell and Bourne Shell and is fully compatible with Bourne Shell.
pdksh: is an extension of ksh provided by the Linux system.
pdksh supports character control, which allows you to suspend, background, wake up, or terminate a program from the command line.

Let's look at the configuration of Bash environment variables in Linux

In Linux, we usually configure environment variable information into different files. Commonly used configuration files are:

  • /etc/profile
  • /etc/bashrc
  • ~/.bash_profile
  • ~/.bashrc
  • ~/.bash _logout

The above configurations are mainly different between interactive login Shell and interactive non-login Shell, and different configurations will be loaded.

Interactive Login Shell

It is to log in to the Linux system, enter your username and password, or su -l. username method

Non-Login Shell

After you enter the system, open a terminal and execute Bash.

/etc/profile

Generally, it is used for system configuration, setting environment information for each user of the system. When a user logs in for the first time, this file is executed and collects shell settings from the configuration files in the /etc/profile.d directory.

Changes to /etc/profile will only take effect after a reboot, and are valid for every user.

/etc/profile.d/

It can be understood as a part of /etc/profile , but the configuration can be split into several files based on category or function, which is clearer and easier to maintain.

/etc/bashrc

This file is executed for each user who runs the Bash Shell. When the Bash Shell is opened, the file is executed and its configuration is effective for each Bash opened by all users using bash. Once modified, you only need to open a new Bash to take effect without restarting.

~/.bash_profile

The file is in the user directory and sets exclusive environment information and startup programs for the current user. The file is executed once when the user logs in and executes the current user's .bashrc file. If there are any changes, a restart is required to take effect.

~/.bashrc

Sets exclusive Bash information for the current user. This file is executed every time a new shell is opened. If there are any modifications, there is no need to restart, just open a new Shell terminal.

~/.bash_logout

This file is executed every time the current user exits the Bash shell.

The above files that require a restart to take effect are temporarily effective through methods such as source ~/.bash_profile , and do not actually restart the computer.

Summarize

This is the end of this article about how to configure Bash environment variables in Linux. For more relevant Linux environment variable configuration content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to configure environment variables in Linux environment
  • A brief introduction to Linux environment variable files
  • Summary of Linux environment variable configuration methods (differences between .bash_profile and .bashrc)
  • Detailed explanation of Linux environment variable configuration strategy
  • A complete guide to Linux environment variable configuration
  • How to configure Java environment variables in Linux system
  • Installation and configuration of Java environment variables under Linux
  • Detailed steps for configuring environment variables in Linux
  • A brief discussion on how to modify/set the environment variable JAVA_HOME under Linux

<<:  Detailed explanation of MySQL event modification events (ALTER EVENT), disabling events (DISABLE), enabling events (ENABLE), event renaming and database event migration operations

>>:  jQuery implements article collapse and expansion functions

Recommend

SQL Aggregation, Grouping, and Sorting

Table of contents 1. Aggregate Query 1. COUNT fun...

Detailed explanation of the use of MySQL sql_mode

Table of contents Preface sql_mode explained The ...

Detailed explanation of the usage of image tags in HTML

In HTML, the <img> tag is used to define an...

Implementation of Nginx forwarding matching rules

1. Regular expression matching ~ for case-sensiti...

Basic knowledge of website design: newbies please read this

Now many people are joining the ranks of website ...

Vue+el-table realizes merging cells

This article example shares the specific code of ...

VMware12.0 installation Ubuntu14.04 LTS tutorial

I have installed various images under virtual mac...

Command to remove (delete) symbolic link in Linux

You may sometimes need to create or delete symbol...

Detailed explanation of HTML basics (Part 1)

1. Understand the WEB Web pages are mainly compos...

Simple usage example of MySQL 8.0 recursive query

Preface This article uses the new features of MyS...

How to locate MySQL slow queries

Preface I believe that everyone has had experienc...

Detailed explanation of eight methods to achieve CSS page bottom fixed

When we are writing a page, we often encounter a ...

MySQL query optimization using custom variables

Table of contents Optimizing sorting queries Avoi...