sh执行脚本命令没有权限也能正常执行

微信公众号:51码农网
专业编程问答社区
www.51manong.com

sh+脚本名称,可以不必事先设定shell的执行权限。因为这个是将test.sh作为参数传给sh(bash)命令来执行的。这时不是test.sh自己来执行,而是被人家调用执行,所以不要执行权限。

[root@iz2ze720onwdpm0gqiky35z 51mn]# ls -lrt test.sh 
-r--r--r-- 1 root root 22 Oct 14 22:34 test.sh
[root@iz2ze720onwdpm0gqiky35z 51mn]# sh test.sh 
hello world

如果直接运行test.sh,就会报权限问题

[root@iz2ze720onwdpm0gqiky35z 51mn]# ./test.sh 
-bash: ./test.sh: Permission denied

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理