So, I\'ve been trying to customize by bash prompt so that it will look like
[feralin@localhost ~]$ _
with colors. I managed to get constant
If you don't want to use the prompt command there's two things you need to take into account:
Working example using a variable
PS1="\$(VALU="\$?" ; echo \$VALU ; date ; if [ \$VALU == 0 ]; then echo zero; else echo nonzero; fi) "
Working example without a variable
Here the if needs to be the first thing, before any command that would override the $?
.
PS1="\$(if [ \$? == 0 ]; then echo zero; else echo nonzero; fi) "
Notice how the \$()
is escaped so it's not executed right away but each time PS1 is used. Also all the uses of \$?