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

17次阅读

共计 369 个字符,预计需要花费 1 分钟才能阅读完成。

微信公众号: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

正文完
 0