Jus*_*yle 42
我知道这是一个陈旧的答案,但是如果有其他人像我一样通过Google绊倒这个问题,这里有一个更详细的解释.
如果你想使搜索路径包含的价值,使其pwd
在时间,你设定的搜索路径,这样做:
export PATH=$PATH:$(pwd)
Run Code Online (Sandbox Code Playgroud)
所以,如果pwd
是/home/me/tmp
,PATH将被设置为$PATH:/home/me/tmp
但是,如果您想要它,那么无论您当前的工作目录是在执行命令时(例如pwd
,任何给定时间的值都在搜索路径中),请执行以下操作:
export PATH=$PATH:.
Run Code Online (Sandbox Code Playgroud)
所以,如果pwd
是/home/me/tmp
,PATH将被设置为$PATH:.
.如果您当前的工作目录包含一个名为的脚本foo
,那么它将在您的PATH中出现.如果将目录更改为不包含的目录,则不再foo
在PATH中找到"foo".
您应该注意,将当前工作目录放在PATH中是一种潜在的安全风险.
对于当前目录,您可以仅使用零长度(空)目录名称。您可以使用首冒号或尾随冒号,或双冒号。这是来自 bash 联机帮助页man bash
:
PATH The search path for commands. It is a colon-separated list of
directories in which the shell looks for commands (see COMMAND EXECUTION
below). A zero-length (null) directory name in the value of PATH
indicates the current directory. A null directory name may appear as two
adjacent colons, or as an initial or trailing colon. The default path
is system-dependent, and is set by the administrator who installs bash.
A common value is
``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''.
Run Code Online (Sandbox Code Playgroud)
如果要将当前所在的目录永久添加到可以使用的PATH变量中
$ echo "export PATH=\$PATH:$(pwd)" >> ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
它将扩展$(pwd)
到当前目录的字符串文字,并将引用的行附加到bashrc.注意\
,\$PATH
需要in 来将扩展扩展$PATH
到其当前值.
$ pwd
/path/to/suuuuuuuuuuuuuuuuuuuuper/long/foo/directory/bin
$ echo "export PATH=\$PATH:$(pwd)" >> ~/.bashrc
$ tail ~/.bashrc -n 1
export PATH=$PATH:/path/to/suuuuuuuuuuuuuuuuuuuuper/long/foo/directory/bin
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
48020 次 |
最近记录: |