Hack 33. PROMPT_COMMAND

Bash shell executes the content of the PROMPT_COMMAND just before displaying the PS1 variable.

ramesh@dev-db ~> export PROMPT_COMMAND="date +%H:%M:%S"

22:08:42
ramesh@dev-db ~>

[Note: This displays the PROMPT_COMMAND and PS1 output on different lines]

If you want to display the value of PROMPT_COMMAND in the same line as the PS1, use the echo -n as shown below.

ramesh@dev-db ~> export PROMPT_COMMAND="echo -n [$(date +%H:%M:%S)]"

[22:08:51]ramesh@dev-db ~>

[Note: This displays the PROMPT_COMMAND and PS1 output on the same line]