简体   繁体   English

bash:显示绝对路径,并在提示符下解析符号链接

[英]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? 是否有可能让我的壳显示完整的当前工作目录,甚至当我cd成一个符号链接? My current PS1 reads 我目前的PS1读取

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 ] . 但是,当我进入链接目录时,它显示(例如) [ ~/LINKEDDIR ]而不是对我来说更有用的东西,例如[ /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. 您不必直接使用\\w转义序列,而必须直接调用pwd实用程序并使用其-P选项来完全扩展任何符号链接。 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时执行一次)。

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

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

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