当我是root用户时运行shell脚本,但是从Makefile调用它时仍获得拒绝权限(仍然以root用户身份) [英] shell script run when I am root but I get a permission denied when it is invoked from a Makefile (still as root)

查看:532
本文介绍了当我是root用户时运行shell脚本,但是从Makefile调用它时仍获得拒绝权限(仍然以root用户身份)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行一个 Make脚本,该脚本会调用Shell脚本.

我可以直接以root用户身份运行shell脚本,但是在makefile上运行make时(仍然以root用户身份),make被拒绝运行同一shell脚本的权限吗?

I can run the shell script directly as root but when running make on the makefile (still as root) make is denied permission to run the same shell script?

Makefile中令人讨厌的那一行是:

The offending line in the Makefile is that one:

PLATFORM=$(shell $(ROOT)/systype.sh)

我可以输入并对系统上每个Makefile脚本的每个PLATFORM变量的值进行硬编码,但这将是毫无意义的修复,我想了解为什么会出现权限被拒绝"错误:

I could go in and hardcode the value of every PLATFORM variable of every Makefile scrip on the system but that would be pointless fix, I'd like to understand why there is that Permission Denied error:

make[1]: execvp: ../systype.sh: Permission denied

PS:即使Shell脚本仅包含lsecho linux权限被拒绝给Make实用程序来运行Shell脚本,shell脚本的内容也不是问题.

PS: The content of the shell script is not the issue even if the shell script only contain ls or echo linux the Permission is Denied to the Make utility to run the shell script.

PS:我并不是专业人士,因此,如果说明与Make有关,请尽可能具体.

PS: I am not a make expert by an mean so if the explanation is related to Make please be as specific as you can.

推荐答案

在上面的评论中,您说手动运行"时使用. scriptname.sh,对吗?您使用.,然后使用scriptname.sh?

In your comments above you say when you "run it manually" you use . scriptname.sh, is that correct? You use . followed by scriptname.sh?

这不是运行脚本,是提供脚本.您说 scriptname.sh将在有和没有x权限的情况下执行,因为它是shell脚本,这是错误的.如果您具有读取权限,则可以 source 脚本.但是除非拥有执行权限,否则您不能执行该脚本.

That does not run the script, that sources the script. Your statement that scriptname.sh will execute with and without the x permission since it is a shell script is wrong. You can source the script if you have read permissions. But you cannot execute the script unless you have execute permissions.

采购"意味着没有启动新的外壳程序:而是您当前的外壳程序(您在其中键入该命令的位置)读取脚本的内容并像键入它们一样运行它们手动插入当前外壳中.最后,在该脚本中执行的所有副作用(目录更改,变量分配等)在您当前的脚本中仍然可用.

"Sourcing" means that a new shell is not started: instead your current shell (where you type that command) reads the contents of the script and runs them just as if you'd typed them in by hand, in the current shell. At the end all the side-effects (directory changes, variable assignments, etc.) that were performed in that script are still available in your current script.

执行"是指将该脚本视为程序,但是该程序是已启动的新外壳,然后该外壳读取脚本的内容并执行该脚本.脚本结束后,shell退出,所有副作用都消失了.

"Executing" means that the script is treated like a program, but the program is a new shell that's started, which then reads the contents of the script and executes it. Once the script ends the shell exits and all side-effects are lost.

make中的$(shell ...)函数将不会为您的脚本提供源代码(除非您在那里也使用了.,而您没有使用).它将尝试运行您的脚本.您显示的错误表明systype.sh没有设置执行位,或者它具有无效的#!.线.我没有想到的其他解释.

The $(shell ...) function in make will not source your script (unless you also use . there, which you did not). It will try to run your script. The error you show implies that either systype.sh did not have the execution bit set, or else that it had an invalid #! line. There's no other explanation I can think of.

如果采购文件确实可以满足您的要求,那么为什么不使用$(shell ...)中与您个人使用相同的方法:

If sourcing the file really does what you want then why not just use the same method in $(shell ...) that you use in your own personal use:

PLATFORM=$(shell . $(ROOT)/systype.sh)

如果更改用户权限无效,那么您确定拥有该脚本的任何用户都与您用来调用make的用户相同吗?您说您正在以root用户身份运行";脚本是root拥有的吗?还是它归您所有,并且您正在运行sudo make或类似版本?

If changing the user permission didn't work, are you sure that whatever user owns the script is the same user you're using to invoke make? You say you're "running as root"; is the script owned by root? Or is it owned by you and you're running sudo make or similar?

我不知道你为什么不只使用:

I don't know why you don't just use:

chmod +x systype.sh

叫它一天.

这篇关于当我是root用户时运行shell脚本,但是从Makefile调用它时仍获得拒绝权限(仍然以root用户身份)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆