简体   繁体   English

当前工作目录以别名输出

[英]Current Working Directory output in an alias

I want to create an alias that will print out the current working directory sub name. 我想创建一个将打印出当前工作目录子名称的别名。

I have this: 我有这个:

BASENAME=${PWD##*/}
alias wai="echo $BASENAME"

This outputs the directory subname of the directory .bashrc is stored in. I want it to be the current working directory. 这将输出目录.bashrc存储的目录子名称。我希望它是当前的工作目录。

Sorry if this is simple, I'm new to bash. 对不起,如果这很简单,我是bash的新手。

The trick is really just in the single quotes. 诀窍就在于单引号。 I believe you can achieve this by doing the following: 我相信你可以通过以下方式实现这一目标:

'echo ${PWD##*/}'

More details: Difference between single and double quotes in Bash 更多细节: Bash中单引号和双引号之间的区别

There is a command for this: 有一个命令:

$ pwd
/path/to/current/directory

Am I missing something? 我错过了什么吗?

Edit based on your comment: 根据您的评论进行修改

alias foo="pwd | rev | cut -d '/' -f1 | rev"

关于什么

alias wai='basename $PWD'

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

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