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 to use the source command in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use the source command in Linux, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

The Linux system source command is often used to re-execute a newly modified initialization file. For example,/etc/profile, bash_profile, when the initialization file is modified, the source command execution does not need to be restarted to take effect.

Linux source command: Common usage: source filepath or. filepath

Function: causes the current shell to read the shell file with filepath path and execute all the statements in the file in turn, usually used to re-execute the initialization file just modified so that it takes effect immediately without logging out and logging back in. For example, when we modify the/etc/profile file and want it to take effect immediately without having to log in again, we can use the source command, such as source /etc/profile.

The source command (from C Shell) is a built-in command of the bash shell; the dot command (.), A dot symbol (from Bourne Shell) is another name for source. This can also be seen in usage.

source filepath and sh filepath,./ Difference between filepath: sh filepath and./when shell script has executable permissions filepath is indistinguishable./ filepath is because the current directory is not in PATH, all ". "is used to represent the current directory.

sh filepath creates a new child shell in which the script's statements are executed. The child shell inherits environment variables from the parent shell, but the child shell is new and its changed variables are not brought back to the parent shell unless export is used.

source filename simply reads the statements in the script and executes them in the current shell in turn, without creating a new subshell. All new and variable changes in the script will be saved in the current shell.

Examples:

Create a new test.sh script with the following content:A=1;

Modify its executable permissions: chmod +x test.sh;

After running sh test.sh, echo $A, appears empty because A=1 is not returned to the current shell;

Run./ After test.sh, it has the same effect;

Run source test.sh or. test.sh, then echo $A, it will display 1, indicating that the variable A=1 is in the current shell;

About "how to use the source command in Linux" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

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