This page is READ-ONLY. It is generated from the old site.
All timestamps are relative to 2013 (when this page is generated).
If you are looking for TeX support, please go to VietTUG.org

bash prompt: '$PWD' vs. "$PWD"

Added by over 3 years ago

To get the basename of current directory in bash's prompt

export PS1="`basename $PWD`> " 

This is quite good but it isn't what you're expected. The prompt won't change since the second cd

$ export PS1="`basename $PWD`> " 
foobar>
foobar> cd /tmp
foobar>              # <-- wrong result

How to fix? Use single quote instead

$ export PS1='`basename $PWD`> '
foobar>
foobar> cd /tmp
tmp>                 # <-- it works :)

Below a fancy version with color

$ export PS1='\033[31m`basename $PWD`\033[0m: '

Comments