时间: 2022-07-15|21次围观|0 条评论

一、背景

之前在本地创建了 shell 脚本,在 iterm 中 cd 到该目录,可以通过 ./xxx.sh 的方式去执行。

今天突然发现报了如下错误:

unable to execute xxx.sh : Operation not permitted

或者

-bash: ./xxx.sh: /usr/bin/env: bad interpreter: Operation not permitted

最近把系统升级为 Monterey 版本,怀疑和系统升级有关系。
unable to execute xxx.sh : Operation not permitted 问题插图

二、分析思路

ls -l 查看权限
unable to execute xxx.sh : Operation not permitted 问题插图1

发现有执行权限

使用 ls -l@ 来查看附加属性
unable to execute xxx.sh : Operation not permitted 问题插图2
搜索里面的几个属性发现一些线索

苹果系统有一个GateKeeper保护机制(自 OSX 10.5 加入)。从互联网上下载来的文件,会被自动打上 com.apple.quarantine 标志,翻译过来就是免疫隔离,系统根据这个附加属性对这个文件作出限制。

三、解决办法

sudo xattr -r -d com.apple.quarantine +目录路径

输入系统密码即可。

unable to execute xxx.sh : Operation not permitted 问题插图3

设置完成后 执行 ./test.sh 发现可以正常执行

创作不易,如果本文对你有帮助,欢迎点赞、收藏加关注,你的支持和鼓励,是我创作的最大动力。
unable to execute xxx.sh : Operation not permitted 问题插图4

原文链接:https://mingmingruyue.blog.csdn.net/article/details/121689012

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《unable to execute xxx.sh : Operation not permitted 问题
   

还没有人抢沙发呢~