I started tweaking around with my bash prompt lately and I find myself not understanding how the escape character works. I have the following:
PS1="\[$RED\]\342\224\214\342\224\200"
In this I get it, \[ escapes the [ character and \xxx escapes my UTF-8 characters. But in the following line I get a weird result:
PS1+="$([·\$?·!=·0·]·&&·echo·\[$RED\]\342\234\227\·)"
This will always print X in my prompt, yet if I escape the first $ it will print it only when exit status of any command is non zero. I do not understand why. Wasn't $(commands) supposed to output the result of given commands? If I escape it like so \$() is the whole sequence escaped or just the dollar sign? If I don't escape why doesn't it print $? It just prints the X. I have the same question for the $ inside the square brackets. Why do I have to escape it?
Also I believe this qualifies as another question but is there any way of printing the actual exit status in my prompt?