bash 如何将当前目录添加到 UNIX 中的搜索路径?

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

How can I add the current directory to the search path in UNIX?

macosbashunixterminal

提问by simge

I cannot fix the command not found errors in UNIX bash. I need to add the current directory to my search path. However, I searched in google but I cannot find anything which tells me the direct solution (since I am in the beginner level and it is hard to understand)

我无法修复 UNIX bash 中未找到命令的错误。我需要将当前目录添加到我的搜索路径中。但是,我在谷歌搜索,但找不到任何可以告诉我直接解决方案的内容(因为我处于初学者级别并且很难理解)

when I write to terminal pwd, it says

当我写信给终端时pwd,它说

/Users/macbook

when I write echo $PATH, it says

当我写的时候echo $PATH,它说

/Users/macbook/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/opt/X11/bin:/Users/macbook/OPT/BIN:/Users/macbook/opt/bin

How can I add the current directory to my search path? Thank you for any help!

如何将当前目录添加到我的搜索路径?感谢您的任何帮助!

回答by qqibrow

try this in your terminal, it should work.

在你的终端试试这个,它应该可以工作。

PATH=$PATH:$(pwd)

回答by Samik

If you want bash to always search the current directory first for the command, not matter in which directory you are currently in, you can add "." to your PATH variable. For that, edit the file .bash_profileor .profilefile in your home directory (first one present) and add the line:

如果你想让 bash 总是先在当前目录中搜索命令,不管你当前在哪个目录,都可以添加“.”。到您的 PATH 变量。为此,编辑主目录中的文件.bash_profile.profile文件(第一个存在)并添加以下行:

PATH=.:$PATH