I want my bash Prompt String 1 to have both the date/time and the return code of the last command. So, I thought I could just do
PS1="\[\e[00;34;01m\]\$(date +'%a %b %e, %T')\[\e[35m\] \$?\[\e[00m\] >> "
Which I thought would give me a blue date (like Thu Jul 2, 01:01:01
) a purple return code and then just >>
(given that the ansi escape sequences produce "normal" colors based on most pallets for terminals). However, it doesn't work.
PS1="\$? >> "
and
PS1="\$(date +\"%a %b %e, %T\") >> "
both work, though, and when I do it the first way, only the first "\$"
gets interpreted and the other only gets interpreted when my bashrc is sourced. (So, the "\$?"
gets evaluated to 0
initially and stays 0
.)
Any thoughts as to why this is happening?
Note: I have even tried PS1='$(date +"%a %b %e, %T") $? >> '
Can anyone else replicate this in Unix bash? If so/if not, please leave a comment.