在Linux中将任何当前目录"./"添加到搜索路径 [英] Adding any current directory './' to the search path in Linux

查看:676
本文介绍了在Linux中将任何当前目录"./"添加到搜索路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux可执行文件的搜索路径中添加任何当前目录'./'?

How do you add any current directory './' to the search path for executables in Linux?

推荐答案

我知道这是一个旧答案,但是如果其他人像我一样通过Google偶然发现了这个问题,则这里有更详细的解释.

I know this is an old answer, but if anyone else stumbles across this question via Google like I did, here's a more detailed explanation.

如果要使其设置时的搜索路径包含值pwd,请执行以下操作:

If you want to make it so that search path contains the value of pwd at the time you set the search path, do:

export PATH=$PATH:$(pwd)

因此,如果pwd/home/me/tmp,则PATH将设置为$PATH:/home/me/tmp

So, if pwd is /home/me/tmp, PATH will be set to $PATH:/home/me/tmp

但是,如果希望使用它,以便执行命令时当前的工作目录是什么(例如,在任何给定时间的pwd值都在搜索路径中),请执行以下操作:

However, If you want it so that whatever your present working directory is at the time you execute a command (ex; the value of pwd at any given time is in the search path), do:

export PATH=$PATH:.

因此,如果pwd/home/me/tmp,则PATH将设置为$PATH:..如果您当前的工作目录包含一个名为foo的脚本,那么它将在您的PATH中找到.如果将目录更改为不包含foo的目录,则在PATH中将不再找到"foo".

So, if pwd is /home/me/tmp, PATH will be set to $PATH:.. If your present working directory contains a script called foo, then it would be fount in your PATH. If you change directories to one that does not contain foo, "foo" will not be found in the PATH any more.

您应该注意,将当前的工作目录放在PATH中会带来潜在的安全风险.

You should note that having your present working directory in your PATH is a potential security risk, however.

这篇关于在Linux中将任何当前目录"./"添加到搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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