xcode 如何通过命令行知道XCode的默认安装目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8061431/
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-14 22:22:38  来源:igfitidea点击:

How can we know the default Installation Directory of XCode through command line?

iphonexcodecommand-lineenvironment-variablesxcode4.2

提问by DShah

Is there a way to know the Default Installation Directoryof XCode through command line? (I know default is /Developer, but what if i changed it to /XCode42, then in this case how can i get path)

有没有办法通过命令行知道XCode的默认安装目录?(我知道默认是/Developer,但是如果我将其更改为/XCode42,那么在这种情况下如何获取路径)

Also where is those environment variables are set and what are the names for those variables? (As in windows we are giving Path for Java)

还有那些环境变量在哪里设置,这些变量的名称是什么?(在 Windows 中,我们为 Java 提供了 Path)

回答by joerick

This will do

这会做

xcode-select --print-path

回答by alinoz

if your xcode direcotry is in the path you can use the command which:

如果您的 xcode 目录在路径中,您可以使用以下命令:

 # which Xcode

this will return the path to the executable (only if it can be found using the PATH environment variable).

这将返回可执行文件的路径(仅当可以使用 PATH 环境变量找到它时)。

to find the enviroment variables open the shell and type (if you are using the bash shell):

要查找环境变量,请打开 shell 并键入(如果您使用的是 bash shell):

 # env

this will display the environment variables.

这将显示环境变量。

if you have the Xcode running you can run a ps command and grep the path from the output:

如果您正在运行 Xcode,则可以运行 ps 命令并从输出中 grep 路径:

# ps -e -o command | grep Xcode | cut -d" " -f 1 | grep -e "Xcode$"

# ps -e -o 命令 | grep Xcode | 剪切 -d" " -f 1 | grep -e "Xcode$"

this will return you the path of the running Xcode (tested on my mac).

这将返回正在运行的 Xcode 的路径(在我的 mac 上测试)。

You can add your Xcode bin directory to your PATH by editing your .bashrc file and adding this line:

您可以通过编辑 .bashrc 文件并添加以下行来将 Xcode bin 目录添加到 PATH 中:

export PATH=$PATH:/Developer/Applications/Xcode.app/Contents/MacOS/

then do a

然后做一个

# source .bashrc

and then you can execute your Xcode form the command line by directly typing Xcode and the which command will return you the path to the Xcode.

然后您可以通过直接键入 Xcode 从命令行执行 Xcode,which 命令将返回 Xcode 的路径。