Using the PROMPT_COMMAND environment variable

suggest change

When the last command in an interactive bash instance is done, the evaluated PS1 variable is displayed. Before actually displaying PS1, bash checks whether PROMPT_COMMAND is set. The value of this variable must be a callable program or script. If this variable is set, that program or script is called before the PS1 prompt is displayed.

# just a stupid function, we will use to demonstrate
# we check the date if Hour is 12 and Minute is lower than 59
lunchbreak(){ 
   if (( $(date +%H) == 12 && $(date +%M) < 59 )); then 
      # and print colored \033[ starts the escape sequence 
      # 5; is the blink attribute
      # 1; means bold
      # 31 means red
      printf "\033[5;1;31mmind the lunch break\033[0m\n";
   else
      printf "\033[33mstill working...\033[0m\n"; 
   fi; 
}

# activating it
export PROMPT_COMMAND=lunchbreak

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents