bash 3.1 gotcha

Callum Lerwick seg at haxxed.com
Thu Jan 12 19:26:23 UTC 2006


For many years, I have had a fancy bash prompt, that contains this:
${PWD/#$HOME/~} This replaces your home dir with a tilde. However, with
bash 3.1, it stopped working:

seg at bigtime:/home/seg
$ rpm -q bash
bash-3.1-2
seg at bigtime:/home/seg
$ echo ${PWD/#$HOME/~}
/home/seg

It works in bash 3.0 and earlier:

seg at hamburger:~
$ rpm -q bash
bash-3.0-31
seg at hamburger:~
$ echo ${PWD/#$HOME/~}
~

I was very confused, until I figured out the ~ was now getting expanded
to $HOME, thus $HOME was getting replaced with $HOME! So escaping the
tilde fixes it:

seg at bigtime:~
$ echo ${PWD/#$HOME/\~}
~

I don't know if this is a bug or not. And may be too obscure for anyone
to care, but there it is.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.fedoraproject.org/pipermail/devel/attachments/20060112/2e120eb3/attachment-0002.bin 


More information about the devel mailing list