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

How the Linux system adds a path to the PATH environment variable

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the Linux system how to add the path to the PATH environment variables, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

In the linux system, the environment variable is the path path of a directory, and setting the environment variable is to store the absolute path of the directory in the linux environment.

Introduction to PATH environment variables: PATH says simply that it is a string variable. When entering a command, LINUX will find the path recorded in PATH.

For example, you can enter the command ls in the root directory / and ls in the / usr directory, but in fact, the command ls is not in these two directories at all. In fact, when you enter a command, LINUX will go to the / bin,/usr/bin,/sbin directory to find the command you entered at this time, and the value of PATH is precisely / bin:/sbin:/usr/bin: …. The colon separates the directory from the directory.

Second, add mode 1. Use the export statement directly, for example:

#! / usr/bin/sh # / etc/profile.d/jdk.sh export PATH=$PATH:/usr/local/jvm/bin or:

# ~ /. Bashrc Export PATH=$PATH:~/.local/bin. The biggest drawback of this method is that it is easy to add repeatedly, especially the statements written in the user's shell configuration file will be repeatedly inserted when the user reloads the shell configuration file. Of course, the duplication caused by reloading the configuration file can basically be solved by writing in the shell configuration file loaded only during login (such as .zlogin of zshell).

two。 With the help of a function in the / etc/profile file of ArchLinux, I found a magic function and wrote it in my .zshrc:

Appendpath () {case ": $PATH:" in *: "$1": *) *) PATH= "${PATH:+$PATH:} $1" esac} appendpath'~ / .local / bin' unset-f appendpath export PATH before adding a path to the PATH variable, it will use the matching mechanism of case to determine whether the path to be added already exists in the PATH variable, so as to determine whether to add it. After the execution is completed, use the uset command to contact the occupation of the function name.

Thank you for reading this article carefully. I hope the article "how to add paths to PATH environment variables in Linux system" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report