Linux下脚本执行命令sh

需要执行权限

任意路径:

输入完整路径及脚本名

例子:

/root/datelog.sh

当前路径:

./脚本名

例子:

./datelog.sh

没有执行权限

任意路径:

sh 完整路径及脚本名

例子:

sh /root/ datelog.sh

当前路径:

sh 脚本名

例子:

sh datelog.sh

原文链接:https://juejin.im/post/5d2480a7f265da1b6836e3

拓展:

PS: source 和 ./的区别

./script 作为一个可执行文件来运行脚本,启动一个子shell来运行它,当执行完脚本之后,又回到了父shell中,所以在子shell中执行的一切操作都不会影响到父shell;
source script 在当前shell环境中从文件名读取和执行命令。
注意:./script 不是 . script ,但是 . script 类似于source script

使用./ 运行脚本的时候,系统变量不会受到影响,而使用source的时候,会影响到系统当前的环境变量。

 

猜你喜欢

转载自www.cnblogs.com/soymilk2019/p/12179554.html