简体   繁体   English

创建以PWD作为变量的别名

[英]Creating an alias that has PWD as variable

I would like to create an alias for the following command: 我想为以下命令创建别名:

cd `pwd | sed 's/\(.*\/main\/lib\).*/\1/'`/h

But I can't seem to pass pwd as a variable. 但是我似乎无法将pwd作为变量传递。 Instead it takes the directory at which the .alias file is located at. 而是使用.alias文件所在的目录。 I have tried using $PWD or '\\$pwd' and I can't seem to get it to work. 我尝试使用$PWD'\\$pwd' ,但似乎无法正常工作。

How can I create an alias that for this command? 如何为该命令创建别名? Any help would be greatly appreciated. 任何帮助将不胜感激。

最好改用一个函数:

hcd() { cd $(sed 's#\(.*/main/lib\).*#\1#' <<< "$PWD")/h; }

它似乎为我工作:

 alias H='cd $(pwd | sed "s=\(main/lib\).*=\1=")/h'

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

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