bash “CDPATH”命令应该如何写在.bashrc文件中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16869971/
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
How should the "CDPATH" command be written in the .bashrc file?
提问by Henry Zhu
I have a directory deep in folders (XAMPP) I'd like to cdinto directly into.
我在文件夹(XAMPP)深处有一个目录,我想cd直接进入。
I run this in the terminal: CDPATH=/Applications/XAMPP/xamppfiles/htdocs/And it works!
我在终端中运行CDPATH=/Applications/XAMPP/xamppfiles/htdocs/它:它有效!
So if I want this to be permanent, I must add this same line to the .bashrcfile. But adding the same line to my .bashrcfile doesn't work.
因此,如果我希望这是永久性的,我必须将同一行添加到.bashrc文件中。但是将同一行添加到我的.bashrc文件中不起作用。
My .bashrcfile contains:
我的.bashrc文件包含:
[ -n "$PS1" ] && source ~/.bash_profile
CDPATH=/Applications/XAMPP/xamppfiles/htdocs/
How should the line look like in the .bashrcfile? Is mines wrong? I've tried putting exportin front of CDPATHand also $CDPATH:${HOME}/Applications/XAMPP/xamppfiles/htdocsbut neither works.
该行在.bashrc文件中应该如何显示?矿山错了吗?我试过放在andexport前面,但都不起作用。CDPATH$CDPATH:${HOME}/Applications/XAMPP/xamppfiles/htdocs
回答by michas
First be aware that CDPATH is considered first, hence you will not be able to easily change to a local directory if the other directory contains a directory with the same name. You will probably add an empty path in front, writing CDPATH=:/Application/....
首先要注意 CDPATH 是最先考虑的,因此如果另一个目录包含同名目录,您将无法轻松更改到本地目录。您可能会在前面添加一个空路径,将CDPATH=:/Application/....
You should not need the exportas this one is only relevant for you shell, not for commands run by your shell. The line as you wrote it should be fine.
您不应该需要 ,export因为这仅与您的 shell 相关,而与您的 shell 运行的命令无关。你写的那一行应该没问题。
Be aware that, depending how you start it, bash will read ~/.bashrcor ~/.bash_profile. Add an echoline in both to debug which file is evaluated in your context.
请注意,根据您的启动方式,bash 将读取~/.bashrc或~/.bash_profile. echo在两者中添加一行以调试在您的上下文中评估哪个文件。
回答by cajwine
If you want directly go to htdocswith cd htdocs, you should enter:
如果你想直接去htdocswith cd htdocs,你应该输入:
export CDPATH=:/Applications/XAMPP/xamppfiles
to your $HOME/.profile(and open new Terminal.app window - or source $HOME/.profile)
到您的$HOME/.profile(并打开新的 Terminal.app 窗口 - 或source $HOME/.profile)
after this, the
在此之后,
cd htdocs
will cd to /Applications/XAMPP/xamppfiles/htdocs
将 cd 到 /Applications/XAMPP/xamppfiles/htdocs
you can also make special alias for it, e.g.:
您还可以为其创建特殊别名,例如:
alias xcd="cd /Applications/XAMPP/xamppfiles/htdocs"

