mac升级系统后operation not permitted

个人博客地址
mac系统升级至12.0.1后,新建执行脚本发现每次都提示

zsh: operation not permitted: ./xxx.sh

之前正常的脚本修改过后也变得无法执行

hanchengxiao@hanchengxiaodeMacBook-Pro xxx % ls -ll
total 40
-rwxrwxrwx@ 1 hanchengxiao  staff    94 11  5 11:11 xxx.sh
-rwxrwxrwx@ 1 hanchengxiao  staff   223 11  5 10:52 xxx.sh
-rw-r--r--@ 1 hanchengxiao  staff  1678 10 18 12:00 xxx.pem
-rwxrwxrwx@ 1 hanchengxiao  staff   253 10 25 14:09 xxx.sh
-rwxrwxrwx@ 1 hanchengxiao  staff   353 11  5 10:56 xxx.sh

发现权限似乎也没什么问题,可为什么变得不能执行了呢
好奇心促使我进一步探究@的隐藏内容

hanchengxiao@hanchengxiaodeMacBook-Pro xxx % ls -ll@
total 40
-rwxrwxrwx@ 1 hanchengxiao  staff    94 11  5 11:11 xxx.sh
    com.apple.TextEncoding    15 
    com.apple.lastuseddate#PS     16 
    com.apple.macl    72 
    com.apple.metadata:kMDLabel_ovflhabut6jrmym5s5csdfq52e    89 
    ↓↓↓↓↓↓↓↓↓↓注意这鬼东西↓↓↓↓↓↓↓↓↓↓↓
    com.apple.quarantine      23
    ↑↑↑↑↑↑↑↑↑↑注意这鬼东西↑↑↑↑↑↑↑↑↑↑↑
-rwxrwxrwx@ 1 hanchengxiao  staff   223 11  5 10:52 xxx.sh
    com.apple.TextEncoding    15 
    com.apple.lastuseddate#PS     16 
    com.apple.macl    72 
    com.apple.metadata:kMDLabel_ovflhabut6jrmym5s5csdfq52e    89 
-rw-r--r--@ 1 hanchengxiao  staff  1678 10 18 12:00 xxx.pem
    com.apple.TextEncoding    15 
    com.apple.lastuseddate#PS     16 
    com.apple.macl    72 
    com.apple.metadata:kMDLabel_ovflhabut6jrmym5s5csdfq52e    89 
-rwxrwxrwx@ 1 hanchengxiao  staff   253 10 25 14:09 xxx.sh
    com.apple.TextEncoding    15 
    com.apple.lastuseddate#PS     16 
    com.apple.macl    72 
    com.apple.metadata:kMDLabel_ovflhabut6jrmym5s5csdfq52e    89 
-rwxrwxrwx@ 1 hanchengxiao  staff   353 11  5 10:56 xxx.sh
    com.apple.TextEncoding    15 
    com.apple.lastuseddate#PS     16 
    com.apple.macl    72 
    com.apple.metadata:kMDLabel_ovflhabut6jrmym5s5csdfq52e    89 

发现不能执行的脚本比其他脚本多了一条属性,虽然不知道这个属性是做什么的但是不影响对它的好奇
百度得知

com.apple.quarantine      23

这个是mac的免疫隔离,系统根据这个附加属性对这个文件作出限制
既然知道了问题就好办了
使用

sudo xattr -r -d com.apple.quarantine $filePath

将文件中的免疫隔离去除,再次执行脚本,又可以愉快地执行了

你可能感兴趣的:(mac升级系统后operation not permitted)