On Fri, Jul 05, 2013 at 12:21:13PM +0000, BASTIDON, Stéphane wrote: > Now my case is a little more complex: > I want my prompt changes colors according to $PWD Then I write something like > that:
This is the kind of thing where I suggest using PROMPT_COMMAND. normal=$(tput sgr0) red=$(tput setaf 1) green=$(tput setaf 2) ... PROMPT_COMMAND=' case $PWD in /usr/local/*) color=$red ;; /var/*) color=$green ;; ... esac ' PS1='\u@\h:\[$color\]\w\[$normal\]\$ ' export normal red green ... PROMPT_COMMAND PS1 The PROMPT_COMMAND will be evaluated before PS1. You can use it to set variables that PS1 will use, all without the horrible speed penalty of a fork/exec.