简体   繁体   English

为“cd”创建别名到包含空格的文件夹中

[英]Create alias for 'cd' into folder containing whitespace

I would like to be able to access some frequently used directories no matter where I am in the directory path.无论我在目录路径中的哪个位置,我都希望能够访问一些经常使用的目录。 I know aliasing can help with this problem, so I've made a few that I've placed into.bashrc.我知道别名可以帮助解决这个问题,所以我做了一些放入.bashrc 中。 Here are some examples:这里有些例子:

alias 'Programming'="cd /mnt/e/Programming/"
alias 'InternetExplorer' = "cd /mnt/c/Internet Explorer/"

The first alias works, but the second does not.第一个别名有效,但第二个别名无效。

Here are the following things that I've tried:以下是我尝试过的以下事情:

alias 'InternetExplorer'="cd '/mnt/c/Internet Explorer/'"
alias 'InternetExplorer'="cd "/mnt/c/Internet Explorer/""
alias 'InternetExplorer'="cd /mnt/c/'Internet Explorer'/"
alias 'InternetExplorer'="cd /mnt/c/"Internet Explorer"/"
alias 'InternetExplorer'="cd /mnt/c/Internet\ Explorer/"

Some of these solutions do work on the command line, but I'm guessing aliasing just reads in everything under quotations as string.其中一些解决方案确实可以在命令行上运行,但我猜别名只是将引号下的所有内容都读取为字符串。 Also, I can always write a function called "Internet Explorer", but conceptually, I feel like alias ing should be the solution.另外,我总是可以写一个名为“Internet Explorer”的 function,但从概念上讲,我觉得alias ing 应该是解决方案。 I appreciate any help.我很感激任何帮助。

When in doubt, use a function instead:如有疑问,请改用 function:

InternetExplorer() { cd "/mnt/c/Internet Explorer"; }
alias InternetExplorer="cd \"/mnt/c/Internet Explorer\""

On cygwin bash, I would use在 cygwin bash 上,我会使用

alias InternetExplorer="cd \"$(cygpath -m '*pasted dir from File Manager*'\""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM