. (source or dot operator)
从当前shell上下文中的filename参数读取并执行命令

语法

  . filename [arguments]

  source filename [arguments]

在bash中,source 是 dot/period ‘.’ 的同义词, 但不在POSIX中,所以为了获得最大兼容性,请使用句点

当使用source运行脚本时,它在现有shell中运行,脚本完成后,脚本创建或修改的任何变量都将保持可用。相反,如果脚本只是作为文件名运行,那么将生成一个单独的子shell(带有一组完全独立的变量)来运行脚本

bash shell可以解释点/句点的其他方式:

点可以表示当前目录 ("./filename")
在正则表达式中, “.” 将匹配任何单个字符

source是内置的bourne shell和POSIX“special”内置

返回状态是执行的最后一个命令的退出状态,如果没有执行命令则返回零。如果找不到filename,或者无法读取,则返回状态为非零

例子

$ source myscript
$ ./myscript

source 命令实例:

linux命令:source ~/.bash_profile ~/.bash_profile source source ~/.bash_profilerootopen.com
linux命令:source ~/.bash_profile ~/.bash_profile source source ~/.bash_profilerootopen.com
2018-02-10 13:36:48

linux命令:source .bashrc .bashrc source source .bashrcrootopen.com
linux命令:source .bashrc .bashrc source source .bashrcrootopen.com
2018-04-22 16:44:48

linux命令:source filename_script.sh filename_script.sh source source filename_script.shrootopen.com
linux命令:source filename_script.sh filename_script.sh source source filename_script.shrootopen.com
2018-02-14 05:18:48

linux命令:source_print(){ set | sed -n "/^$1/,/^}$/p"; }; }; "/^$1/,/^}$/p"; -n sed | set source_print(){ source_print(){ set | sed -n "/^$1/,/^}$/p"; };rootopen.com
linux命令:source_print(){ set | sed -n "/^$1/,/^}$/p"; }; }; "/^$1/,/^}$/p"; -n sed | set source_print(){ source_print(){ set | sed -n "/^$1/,/^}$/p"; };rootopen.com
2018-04-29 04:37:48

linux命令:source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g ) ) \([0-9]\)/\=\1/'g 's/ -e sed | /g' 's/\s\{1,\}/ -e sed | 's/\//#/g' sed | -r/g' 's/#define/declare -e sed | /usr/include/sysexits.h EX_.*' '^#define <(egrep source source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g )rootopen.com
linux命令:source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g ) ) \([0-9]\)/\=\1/'g 's/ -e sed | /g' 's/\s\{1,\}/ -e sed | 's/\//#/g' sed | -r/g' 's/#define/declare -e sed | /usr/include/sysexits.h EX_.*' '^#define <(egrep source source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g )rootopen.com
2018-01-04 03:55:48

linux命令:source ~/.bashrc ~/.bashrc source source ~/.bashrcrootopen.com
linux命令:source ~/.bashrc ~/.bashrc source source ~/.bashrcrootopen.com
2018-03-05 12:46:48

linux命令:source MYFILE.sql MYFILE.sql source source MYFILE.sqlrootopen.com
linux命令:source MYFILE.sql MYFILE.sql source source MYFILE.sqlrootopen.com
2018-03-14 23:26:48

Linux的Bash命令行(A-Z排序)