简体   繁体   中英

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.

Sorry if this is simple, I'm new to 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

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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