Ubuntu中source、sh、bash、./ 执行shell脚本的区别

source命令用法

source test.sh

作用:在当前 bash 环境下读取并执行 test.sh 中的命令。该 test 文件可以无 “执行权限”

bash和sh命令用法

bash test.sh
或
sh test.sh

作用:打开一个子shell来执行test.sh中的命令。该test文件也可以无”执行权限”

./命令用法

./test.sh

作用:打开一个子shell来执行test.sh中的命令。该test文件需要”执行权限”

补:修改文件执行权限

chmod 777 ./test.sh

详细内容见:http://www.runoob.com/linux/linux-file-attr-permission.html

猜你喜欢

转载自blog.csdn.net/D_pens/article/details/81352437