You can use this code.
[user1@myhost ~]myfunc() { DIR=`pwd`;if [ "$DIR" = "/home/user1" ]; then export PS1="[\e[1;32m\u\e[m@\e[1;34m\h\e[m \e[1;33m\W\e[m]" ;else export PS1="[\w]";fi; }
[user1@myhost ~]PROMPT_COMMAND="myfunc"
[user1@myhost ~]cd /tmp
[/tmp]cd
[user1@myhost ~]cd /etc
[/etc]cd
[user1@myhost ~]
When I change the directory, the request changes.
source
share