bash - PS1 can't have two "\$"? -


i want bash prompt string 1 have both date/time , return code of last command. so, thought do

ps1="\[\e[00;34;01m\]\$(date +'%a %b %e, %t')\[\e[35m\] \$?\[\e[00m\] >> " 

which thought give me blue date (like thu jul 2, 01:01:01) purple return code , >> (given ansi escape sequences produce "normal" colors based on pallets terminals). however, doesn't work.


ps1="\$? >> " 

and

ps1="\$(date +\"%a %b %e, %t\") >> " 

both work, though, , when first way, first "\$" gets interpreted , other gets interpreted when bashrc sourced. (so, "\$?" gets evaluated 0 , stays 0.)

any thoughts why happening?

note: have tried ps1='$(date +"%a %b %e, %t") $? >> '

can else replicate in unix bash? if so/if not, please leave comment.

i don't know why bash ignores second \$, try using \d format date:

ps1="\[\e[00;34;01m\]\d{%a %b %e, %t}\[\e[35m\] \$?\[\e[00m\] >> " 

this works me under bash version 4.2.46


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -