Linux命令完全指南

Linux source命令使用详解

Shell source命令用于在当前Shell环境中从指定文件读取和执行命令,命令返回退出状态。

语法

1
source filename [arguments]

参数

  • filename:要执行的文件
  • arguments(可选):传递给文件的参数

返回值

source返回文件最后一个命令的返回值,如果文件不能读取则会失败

错误用法

  • 文件在$PATH中找不到。
  • 文件未给出。

例子

读取和执行/root/.bash_profile文件。

1
[root@localhost ~]# source ~/.bash_profile