Detailed explanation of .bash_profile file in Linux system

Detailed explanation of .bash_profile file in Linux system

1. Environment variable $PATH:

Linux is a多用戶操作系統, and each user has his or her own dedicated operating environment. The environment used by the user is defined by a series of variables, which are called環境變量. System environment variables are usually in大寫.

Each user can modify their own environment variables as needed to meet their own usage requirements. Common environment variables are as follows:

insert image description here

In Shell , the dollar sign $ is used to reference environment variables, and the echo command can be used to view the value of a specific environment variable.

For example, to view the value of PATH:

 echo $PATH 

insert image description here

You can view all the system environment variable settings by using the env or printenv command. The following shows the result of the env command (partial):

 TERM=xterm
SHELL=/bin/bash
USER=leo
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
HOME=/home/leo
LANGUAGE=zh_CN:zh:en_US:en
LOGNAME=leo

2. Modify environment variables:

Logged-in users can modify and set environment variables as needed. To modify environment variables in Linux,既可以在終端通過Shell 命令修改,也可以通過修改系統的配置文件來進行.

2.1 Modify the system configuration file (recommended)

By modifying the system configuration file, you can achieve the purpose of永久改變the environment variables. After modifying a configuration file, run the file in Shell to make the new settings take effect, or log in again to use the new variables.

Running files can be operated in the same way as source 文件, for example:

 source ~/.bash_profile

Usually modify全局配置文件/etc/profile or用戶配置文件~/.bashrc (some distributions are ~/.bash_profile ) file:

insert image description here

For example:

insert image description here

 PATH=$PATH:$HOME/bin

Specific insights are as follows:

The code $HOME is an environment variable, which represents the home folder of the currently logged in user. (It's the one in the home directory)

The code $HOME/bin refers to the bin subdirectory under the home folder, which represents the internal subdirectory of the folder. (Note that it is not the root directory)

PATH=$PATH:$HOME/bin This code sets the PATH environment variable. Use the equal sign to set the environment variable, : the colon is a separator. When adding environment variables on Windows ; separate them with a semicolon and append them afterwards. Similarly, on Mac, use : to separate the characters and append them.

$PATH:$HOME/bin means that while retaining the original $PATH environment variable, $HOME/bin is added as the new $PATH environment variable. There are many variables in computers, which are mainly used in the management of system files.

Note: The path environment variable is PATH, but add a $ in front when quoting it, that is, $PATH

insert image description here

2.2 Temporary settings

Setting environment variables through Shell 命令is often used to temporarily set environment variables. Once the current terminal is closed or a new terminal is opened, the set environment variables will be lost. You can directly use the equal sign (=) to assign a value to a variable, or use the export command to assign a value to a variable. Usage:

 variable = $variable: add variable value #method 1export variable = $variable: add variable value #method 2

For example:

picture

The newly added variable value can be placed at the end of the original variable value (variable: new variable value), at the beginning of the original variable value (new variable value: variable: new variable value), or at the beginning of the original variable value (new variable value: variable: new variable value).

3. Purpose of bash_profile

In .bash_profile, it is often used to configure environment variables and some user-defined aliases, etc.

insert image description here

Summarize

This is the end of this article about the detailed explanation of the .bash_profile file in the Linux system. For more relevant Linux .bash_profile file content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of Linux environment variable configuration methods (differences between .bash_profile and .bashrc)
  • What is the difference between .bash_profile and .bashrc in Linux

<<:  Summary of CSS3 practical methods (recommended)

>>:  Detailed explanation of Vue's keyboard events

Recommend

Detailed explanation of MySQL database binlog cleanup command

Overview Today I will mainly share how to correct...

Getting Started Tutorial for Beginners: Domain Name Resolution and Binding

So after registering a domain name and purchasing...

Detailed explanation of how to implement secondary cache with MySQL and Redis

Redis Introduction Redis is completely open sourc...

Centos7 mysql database installation and configuration tutorial

1. System environment The system version after yu...

Various methods to restart Mysql under CentOS (recommended)

1. MySQL installed via rpm package service mysqld...

How to understand JavaScript modularity

Table of contents 1. Browser support 2. export ex...

Detailed tutorial for downloading and installing mysql8.0.21

Official website address: https://www.mysql.com/ ...

Ubuntu 18.04 MySQL 8.0 installation and configuration method graphic tutorial

This article shares the installation and configur...

Detailed explanation of Vue filters

<body> <div id="root"> <...

Advantages of MySQL covering indexes

A common suggestion is to create indexes for WHER...

Example code of vue custom component to implement v-model two-way binding data

In the project, you will encounter custom public ...

Two ways to exit bash in docker container under Linux

If you want to exit bash, there are two options: ...

How to use geoip to restrict regions in nginx

This blog is a work note environment: nginx versi...

How to set up Windows Server 2019 (with pictures and text)

1. Windows Server 2019 Installation Install Windo...