-bash: otool: command not found,你能教 bash 一个默认位置来查找命令吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11157277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:33:36  来源:igfitidea点击:

-bash: otool: command not found, Can you teach bash a default location to look for a command?

macosbashshellotool

提问by Orchid

I can find the tool command in my filesystem under:

我可以在我的文件系统中找到工具命令:

/Applications/Xcode.app/Contents/Developer/usr/bin/otool

If I specify that entire path, otool will work.

如果我指定整个路径,otool 将起作用。

/Applications/Xcode.app/Contents/Developer/usr/bin/otool -tV hello -p _main

However, since I have to be inside the folder of the hello.c file I'm referencing, bash won't find otool automatically if I just type

但是,由于我必须在我引用的 hello.c 文件的文件夹中,如果我只输入 bash 将不会自动找到 otool

otool -tV hello -p _main

I've had this same problem with a number of commands. Is there any way to set up bash so it automatically finds otool (and similar commands), without me having to writing out the entire path name each time?Thanks!

我在使用许多命令时遇到了同样的问题。有什么方法可以设置 bash 以便它自动查找 otool(和类似命令),而不必每次都写出整个路径名?谢谢!

Note: If it matters, I'm using a Mac.

注意:如果重要的话,我使用的是 Mac。

Note 2: I've read through a ton of the "Command not found" threads but none seem to answer the question of teaching bash where to look for a command by default. I feel like this question should have been answered somewhere, but haven't come across it yet. Since the only programs I'll be working with any time soon will be iOS/Xcode related, this is worthwhile shortcut.

注 2:我已经阅读了大量“未找到命令”线程,但似乎没有一个能回答教 bash 默认在哪里查找命令的问题。我觉得这个问题应该在某处得到回答,但还没有遇到。由于我将很快使用的唯一程序将与 iOS/Xcode 相关,因此这是一个值得的捷径。

回答by Fred Foo

PATH=$PATH:/Applications/Xcode.app/Contents/Developer/usr/bin

Put this in your ~/.bashrcto have it persist.

把它放在你的~/.bashrc里面让它坚持下去。

回答by Tim

You can also Try using alias to do this. e.g.

您也可以尝试使用别名来执行此操作。例如

$ alias otool='/Applications/Xcode.app/Contents/Developer/usr/bin/otool'

$别名otool='/Applications/Xcode.app/Contents/Developer/usr/bin/otool'

You can also add this in your bashrc/profile file.

您也可以将其添加到 bashrc/profile 文件中。