Home  >  Article  >  Operation and Maintenance  >  How to use the source command in linux

How to use the source command in linux

小老鼠
小老鼠Original
2024-03-14 09:40:331348browse

In Linux, the source command is usually used to re-execute the newly modified initialization file so that it takes effect immediately without having to log out and log in again. Its basic usage is: source filename, where filename must be an executable script file.

How to use the source command in linux

In Linux, the source command is usually used to re-execute the newly modified initialization file so that it takes effect immediately without having to log out and log in again. Its basic usage is: source filename, where filename must be an executable script file. Another equivalent way of writing is to use dot notation: . filename. Note that there is a space after the "." sign.

The source command is a built-in command of the bash shell. Its function is to notify the current shell to read the file with the path filename and execute all the statements in the file in sequence. The source command will force execution of all commands in the script, regardless of file permissions. When you use the source command to execute a script, the script will be executed in the current shell environment, which means that all new and variable statements in the script will be saved in the current shell, instead of creating a new subshell like using sh filename. to execute the script.

For example, when you modify the /etc/profile file and want it to take effect immediately without having to log in again, you can use the source command, such as "source /etc/profile". Similarly, if you modify initialization files such as .bash_profile or .bash_rc and want them to take effect immediately, you can also use the source command.

Overall, the source command is a powerful tool in Linux systems that allows you to immediately apply changes to scripts or initialization files without having to log out and log back in.

The above is the detailed content of How to use the source command in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn