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 source Command in linux

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

Share

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

This article mainly introduces the use of the source command in linux, which is very detailed and has a certain reference value. Friends who are interested must finish it!

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

The function of the linux source command is to make the current shell read into the shell file with the path filepath and execute all the statements in the file in turn; it is usually used to re-execute the initialization file that has just been modified to make it take effect immediately, and the syntax of this command is "source filepath".

This article operating environment: linux5.9.8 system, PHP7.1 version, DELL G3 computer

Linux source command:

Common usage: source filepath or. Filepath

Function: make the current shell read into the shell file with the path of filepath and execute all the statements in the file in turn, which is usually used to re-execute the initialization file that has just been modified to make it effective immediately without having to log out and log 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 source commands, such as source / etc/profile.

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

Differences between source filepath and sh filepath,. / filepath:

When shell scripts have executable permissions, there is no difference between using sh filepath and. / filepath. . / filepath is because the current directory is not in PATH, all "." Is used to represent the current directory.

Sh filepath re-creates a child shell and executes the statements in the script in the child shell. The child shell inherits the environment variables of 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 child shell. Then all statements in the script that create new and change variables will be saved in the current shell.

Examples are as follows:

Create a new test.sh script with the following content: Abeli1

Modify its executable permissions: chmod + x test.sh

After running sh test.sh, echo $An is displayed as empty because Agg1 is not passed back to the current shell

After running. / test.sh, the effect is the same.

Run source test.sh or. Test.sh, and then echo $A, then 1 is displayed, indicating that the variable of Apati1 is in the current shell

The above is all the contents of the article "how to use the source command 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