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

查看:34
本文介绍了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).

维基百科上有一个有点简洁的解释维基百科,但基本上它用于定义在哪里搜索可执行文件(无论是二进制文件、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 shell 之外,几乎所有的情况都可以缩短为:

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

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

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

(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 的配置文件(可以是 ~/.profile~/.bashrc~/.zshrc... 取决于你的 shell),并且不引用 $PWD,而是引用它扩展到的任何内容.实现此目的的一种方法是执行以下操作:

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天全站免登陆