简体   繁体   中英

bash: displaying absolute path with symlinks resolved in prompt

Is it possible to have my shell display the full current working directory, even when I cd into a symlink? My current PS1 reads

PS1="
[ \w ] 
=> "

However when I cd into a linked directory, it displays (for example) [ ~/LINKEDDIR ] instead of something more useful to me such as [ /var/etc/bin/the/actual/path ] .

Is there anyway to change that?

Instead of using the \\w escape sequence, you'll have to call the pwd utility directly and use its -P option to fully expand any symlinks. The following should work (note the single quotes, so that the command substitution is executed every time the prompt is displayed, rather than just once when PS1 is defined).

PS1='\n[ $(pwd -P) ]\n=> '

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