Why doesn't my bash prompt update?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Your bash prompt -- the text that appears before every command you type -- is controlled by environment variables like PS1. When it stops updating (for example, no longer showing the current directory or git branch), it usually means the shell is not re-evaluating the prompt string between commands. This article explains the most common causes and how to fix each one.
How the Bash Prompt Works
Bash evaluates the PS1 variable each time it is about to display a new prompt. If PS1 contains special escape sequences (like \w for the working directory or \u for the username), bash expands them on every prompt render. Here is a typical prompt definition:
The key detail is that bash only expands the built-in escape sequences (\u, \h, \w, etc.) by default. If you want to run a command every time the prompt renders, you need to use PROMPT_COMMAND or embed a command substitution correctly.
Cause 1: Using Double Quotes Instead of Single Quotes
This is by far the most common mistake. When you define PS1 with double quotes, the shell evaluates command substitutions immediately -- at definition time -- rather than at display time.
With single quotes, the $(...) expressions are stored literally in PS1 and evaluated fresh every time bash renders the prompt. With double quotes, they are expanded once and never change.
For this deferred evaluation to work, you also need the promptvars shell option enabled (it is on by default):
Cause 2: Overridden by Another Config File
Bash sources multiple configuration files in a specific order, and a later file can overwrite your customized PS1. The loading order for a login shell is:
/etc/profile~/.bash_profile(or~/.bash_loginor~/.profile)~/.bashrc(if sourced by~/.bash_profile)
For a non-login interactive shell (like opening a new terminal tab), only ~/.bashrc is sourced. Common issues include:
Check the bottom of your ~/.bashrc for tools that modify PS1. Run echo "$PS1" in your terminal to see the current value and compare it against what you set in your config.
Cause 3: PROMPT_COMMAND Resets PS1
The PROMPT_COMMAND variable holds a command (or function) that bash runs before displaying each prompt. Some frameworks and tools set PROMPT_COMMAND to a function that rebuilds PS1 from scratch, overriding your changes.
To diagnose this, inspect the current value:
If a tool is overriding your prompt through PROMPT_COMMAND, you have two options: modify the tool's prompt function, or set your own PROMPT_COMMAND after the tool's initialization.
Cause 4: Running in a Non-Interactive or Non-Bash Shell
If your prompt never updates at all, verify that you are actually running bash and that the shell is interactive:
If $0 shows sh, zsh, or dash, you are not in bash and PS1 escape sequences like \w will not work. On macOS, the default shell is zsh since Catalina, so ~/.bashrc changes have no effect unless you explicitly run bash.
Cause 5: Subshell or Script Context
If you set PS1 inside a script, the change only affects that script's subshell and vanishes when the script exits. To make changes persist, source the file instead of executing it:
Dynamic Prompts with PROMPT_COMMAND
For prompts that show dynamic information (like the current git branch), use PROMPT_COMMAND to rebuild PS1 before each prompt display:
Common Pitfalls
- Double-quoting
PS1with command substitutions: The commands run once at assignment time and the prompt becomes static. Always use single quotes whenPS1contains$(...). - Editing the wrong config file: On macOS (zsh default) or systems using
~/.profile, changes to~/.bashrcmay never be loaded. Verify which file your shell actually sources. - Forgetting to
sourceafter editing: Changes to~/.bashrcdo not take effect in already-open terminals until you runsource ~/.bashrcor open a new terminal. PROMPT_COMMANDconflicts: Tools like conda, virtualenv, and starship set their ownPROMPT_COMMAND. If you override it, you may break their integration. Append to it instead:PROMPT_COMMAND="my_func;$PROMPT_COMMAND".- Disabling
promptvars: Ifshopt -u promptvarshas been set (rarely done intentionally), bash stops expandingPS1variables and command substitutions entirely.
Summary
- Always define
PS1with single quotes so command substitutions are evaluated at display time, not definition time. - Check
~/.bashrc,~/.bash_profile, andPROMPT_COMMANDfor tools that silently override your prompt. - Verify you are running an interactive bash shell and not zsh, dash, or a non-interactive session.
- Use
source(not execution) to apply prompt changes from a script to your current shell. - Use
PROMPT_COMMANDfor dynamic prompt elements like git branches or virtual environment names.

