在 mac 提示“权限被拒绝"上运行脚本 [英] Run script on mac prompt "Permission denied"

查看:48
本文介绍了在 mac 提示“权限被拒绝"上运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 mac 新手,对终端命令不熟悉,我将 dvtcolorconvert.rb 文件放在我卷的根目录下,这个 ruby​​ 脚本可以将 xcode 3 主题转换为 xcode 4 主题格式, 这是 xxxxxxxx.dvtcolortheme 格式.

I'm new to mac with not familiar on terminal command, i put the dvtcolorconvert.rb file on root directory of my volume, this ruby script can converting xcode 3 themes into xcode 4 themes format, which is xxxxxxxx.dvtcolortheme format.

然后在终端上运行脚本/dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme,但总是提示Permission denied".

Then run the script /dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme on terminal, but it's always prompt "Permission denied".

这有什么问题吗?有人可以帮我解决这个问题吗?谢谢.

what's wrong with this? Anybody can help me solve this problem? Thanks.

推荐答案

请在尝试使用 sudo

尝试运行 sudo/dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme

sudo 命令以超级用户"或root"权限执行其后的命令.这应该允许您从命令行执行几乎所有内容.也就是说,不要这样做!如果您在计算机上运行脚本并且不需要它来访问操作系统的核心组件(我猜你不是因为你在你的主目录 (~/)) 中调用脚本,那么它应该从你的主目录运行,即:

The sudo command executes the commands which follow it with 'superuser' or 'root' privileges. This should allow you to execute almost anything from the command line. That said, DON'T DO THIS! If you are running a script on your computer and don't need it to access core components of your operating system (I'm guessing you're not since you are invoking the script on something inside your home directory (~/)), then it should be running from your home directory, ie:

~/dvtcolorconvert.rb ~/Themes/ObsidianCode.xccolortheme

将其移动到 ~/或子目录并从那里执行.您永远不应该在那里遇到权限问题,也不会有访问或修改对您的操作系统至关重要的任何内容的风险.

Move it to ~/ or a sub directory and execute from there. You should never have permission issues there and there wont be a risk of it accessing or modifying anything critical to your OS.

如果您仍然遇到问题,您可以通过在与 ruby​​ 脚本相同的目录中运行 ls -l 来检查文件的权限.你会得到这样的东西:

If you are still having problems you can check the permissions on the file by running ls -l while in the same directory as the ruby script. You will get something like this:

$ ls -l  
total 13  
drwxr-xr-x    4 or019268 Administ    12288 Apr 10 18:14 TestWizard  
drwxr-xr-x    4 or019268 Administ     4096 Aug 27 12:41 Wizard.Controls  
drwxr-xr-x    5 or019268 Administ     8192 Sep  5 00:03 Wizard.UI  
-rw-r--r--    1 or019268 Administ     1375 Sep  5 00:03 readme.txt

您会注意到 readme.txt 文件在左侧显示 -rw-r--r--.这显示了该文件的权限.从右边开始的 9 个字符可以分成 3 个字符为一组的 'rwx'(读、写、执行).如果我想为这个文件添加执行权限,我将执行 chmod 755 readme.txt 并且该权限部分将变为 rwxr-xr-x.我现在可以通过运行 ./readme.txt(./告诉 bash 在当前目录中查找预期命令而不是搜索 $PATH 变量)来执行此文件.

You will notice that the readme.txt file says -rw-r--r-- on the left. This shows the permissions for that file. The 9 characters from the right can be split into groups of 3 characters of 'rwx' (read, write, execute). If I want to add execute rights to this file I would execute chmod 755 readme.txt and that permissions portion would become rwxr-xr-x. I can now execute this file if I want to by running ./readme.txt (./ tells the bash to look in the current directory for the intended command rather that search the $PATH variable).

schluchc 暗指查看 chmod 的手册页,通过运行 man chmod.这是获取给定命令文档的最佳方式,man

schluchc alludes to looking at the man page for chmod, do this by running man chmod. This is the best way to get documentation on a given command, man <command>

这篇关于在 mac 提示“权限被拒绝"上运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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