Bash command execution after

Executing Commands After Running a Bash Command

Introducing how to execute commands after running a command in Bash on the command line of Linux computers and servers. The value of <code>$PROMPT_COMMAND</code> is executed as a command before the prompt is updated with PS1. In other words, it's executed after command execution...

Shou Arisaka
1 min read
Oct 29, 2025

Introducing how to execute commands after running a command in Bash on the command line of Linux computers and servers. The value of $PROMPT_COMMAND is executed as a command before the prompt is updated with PS1. In other words, itโ€™s executed after command execution.

export PROMPT_COMMAND="echo y"

Concrete example

command line - How to share history between terminal tabs? - Ask Different

export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Note that when you start bash from bash, .bashrc is loaded multiple times, and in that case, initialization processing is necessary. Itโ€™s good to write export PROMPT_COMMAND= near the beginning of .bashrc.

Share this article

Shou Arisaka Oct 29, 2025

๐Ÿ”— Copy Links