在Mac(UNIX)系统上,PATH是什么? [英] What is PATH on a Mac (UNIX) system?

查看:186
本文介绍了在Mac(UNIX)系统上,PATH是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个项目,从git风暴:
https://github.com/nathanmarz/storm/wiki/Setting-开发环境

I'm trying to setup a project, storm from git:
https://github.com/nathanmarz/storm/wiki/Setting-up-development-environment

下载Storm发行版,将其解压缩,然后将解压缩后的bin/目录放在PATH中

Download a Storm release , unpack it, and put the unpacked bin/ directory on your PATH

我的问题是:PATH是什么意思?他们到底要我做什么?

My question is: What does PATH mean? What exactly do they want me to do?

有时我会看到一些/bin/path,$ PATH或echo PATH.

Sometimes I see some /bin/path, $PATH, or echo PATH.

有人可以解释PATH的概念吗,这样我以后就可以轻松地设置所有内容,而不必盲目地按照说明进行操作?

Can someone explain the concept of PATH, so I can setup everything easily in the future without just blindly following the instructions?

推荐答案

PATH是UNIX(和类似UNIX的系统,例如GNU/Linux)系统中的一种特殊环境变量,shell经常使用和操纵它.事物也可以使用它.)

PATH is a special environment variable in UNIX (and UNIX-like, e.g. GNU/Linux) systems, which is frequently used and manipulated by the shell (though other things can use it, as well).

关于Wikipedia的在哪里搜索可执行文件(二进制文件,shell脚本等).

There's a somewhat terse explanation on wikipedia, but basically it's used to define where to search for executable files (whether binaries, shell scripts, whatever).

您可以使用简单的shell命令找出当前PATH设置为什么:

You can find out what your current PATH is set to with a simple shell command:

: $; echo $PATH

(注意:: $;旨在表示您的shell提示符;对于您而言,它可能有所不同;只要知道您的提示符是什么,这就是我用该字符串表示的内容.)

(Note: the : $; is meant to represent your shell prompt; it may be something very different for you; just know that whatever your prompt is, that's what I'm representing with that string.)

根据您的系统和先前的配置,该值将有所不同,但是输出的一个非常简单的示例可能是:

Depending on your system and prior configuration, the value will vary, but a very simple example of the output might be something like:

/usr/bin:/bin:/usr/local/bin

这是一个用冒号(:)分隔的目录列表,可在其中搜索可执行文件(诸如ls等),简而言之,当您尝试从Shell中执行命令时(或(以某些方式从其他程序中),它将按顺序搜索此列表中的每个目录,以查找您提供的名称的可执行文件,然后运行找到的第一个文件.这就是您的问题所在的概念.

This is a colon(:)-separated list of directories in which to search for executable files (things like ls, et cetera.) In short, when you try to execute a command from your shell (or from within some other program in certain ways), it will search through each of the directories in this list, in order, looking for an executable file of the name you're provided, and run the first one it finds. So that's the concept, per your question.

此文档告诉您要做的是将解压缩软件的目录(尤其是其bin子目录)添加到您的$PATH变量中.如何执行此操作取决于您所使用的外壳,但是对于大多数情况而言( Bourne -兼容的Shell),如果您位于bin目录所在的目录中,则应该能够执行以下操作:

From there, what this documentation is telling you to do is to add the directory where you've unpacked the software, and in particular its bin subdirectory, into your $PATH variable. How to do this depends a bit on which shell you're using, but for most (Bourne-compatible) shells, you should be able to do something like this, if you're in the directory where that bin directory is:

: $; PATH="$PATH:$PWD/bin"; export PATH

除了实际的Bourne壳外,几乎可以将其缩短为:

In just about all but an actual Bourne shell, this can be shortened to:

: $; export PATH="$PATH:$PWD/bin"

(我不会费心解释与CSH兼容的外壳(因为:我同意您不要使用它们),但是如果由于某种原因恰好是您选择的环境,也可以在它们中进行类似的操作.)

(I won't bother explaining for CSH-compatible shells (because: I agree with other advice that you don't use them), but something similar can be done in them, as well, if that happens to be your environment of choice for some reason.)

不过,大概您希望将其保存到特定于Shell的配置文件(取决于您的Shell,可以为~/.profile~/.bashrc~/.zshrc ...),而无需引用,但无论它扩展到了什么.您可能会完成此操作的一种方法是执行以下操作:

Presumably, though, you'll want to save this to a shell-specific configuration file (could be ~/.profile, ~/.bashrc, ~/.zshrc... depending on your shell), and without reference to $PWD, but rather to whatever it expanded to. One way you might accomplish this would be to do something like this:

: $; echo "export PATH=\"\$PATH:$PWD/bin\""

,然后将结果行复制/粘贴到适当的配置文件中.

and then copy/paste the resulting line into the appropriate configuration file.

当然,您还可以通过其他方式生成适当的命令,尤其是当$PWD当前不在该bin目录所在的位置时.

Of course you could also generate the appropriate command in other ways, especially if your $PWD isn't currently where that bin directory is.

另请参阅:

这篇关于在Mac(UNIX)系统上,PATH是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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