bashmacosterminalps1

Mac export PS1 doesn't handle escaped commands


I'm just trying to change the terminal prompt in macOS Sierra. Nothing fancy, I just need to know the current path.

In my ~/.bash_profile I'm adding

export PS1="[\w] > "

I know that \w should be replaced by current full path but none of the escape characters seems to work on my Mac. I just get the same string without evaluating, so my prompt looks like

[\w] >

I've tried many different PS1 strings without luck. I also tried using .bashrc instead bash_profile.

Any ideas?


Solution

  • I suspect you're running a shell that doesn't understand the \w escape in the prompt string. If echo $0 returns something other than -bash, you have to use whatever that shell understands: