0

To change the back color my command is :

PS1='\[\033[46m\]'

This works fine for bash but in ksh it will but a [] in front of my server.

Example :

Bash :

[USER@SERVER] (in color)

Ksh :

[][USER@SERVER] (in color)

If I wanted it to work in Ksh I would have to write it like this :

PS1='\033[46m'

Any ideas on making it work for both ksh and bash ?

  • Unless I didn't understand the post it's telling me to use ESC characters (which I have done). This allowed me to no longer have overwritting issues in bash but in ksh adds a [] to my prompt – The_Badger_Novice Aug 9 '18 at 12:00
  • 'libshedit` is even older than line editing support in ksh and has no problems with character with of the characters in the prompt, since it uses backspace or "print char" to navigate in the command line. The brackets you have with bash are non standard. – schily Aug 9 '18 at 12:02
  • Is that ksh88, ksh93 or one of the pdksh derivatives? – Stéphane Chazelas Aug 9 '18 at 12:15
0
if [ "$SHELL" == '/bin/bash' ] ; then
  PS1='\[\033[46m\]'
else
  PS1='\033[46m'
fi 
  • What exactly is the $SHELL ? – The_Badger_Novice Aug 9 '18 at 12:59
  • SHELL is an environment variable that is set to the current shell (for ksh it is set to /bin/ksh). Enter env in a terminal to see all variables, or echo $SHELL to see this specific one. – nst0022 Aug 9 '18 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.