GREEN="\e[1;32m"
RED="\e[1;31m"
NONE="\e[m"
get_exit_status(){
es=$?
if [ $es -eq 0 ]
then
echo -e "${GREEN}${es}${NONE}"
else
echo -e "${RED}${es}${NONE}"
fi
}
get_path(){
#dummy function
echo "PATH"
}
PROMPT_COMMAND='exitStatus=$(get_exit_status)'
The following gives me the correct exitStatus but colour variables are not expanded:
PS1='${RED}\h $(get_path) ${exitStatus}${NONE} '
However, the one below, gives me the colours but the exit status does not update:
PS1="${RED}\h $(get_path) ${exitStatus}${NONE} "
What is the right way to do this? How can I fix this so that the exitStatus and colours both work?