Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

According to this StackOverflow post, it is possible have a colored prompt in KornShell. I have not been able to figure out how to do this. I am able to use color:

echo -e "\033[34mLinux\033[00m"

gives a blue "Linux" output, as does:

printf "\033[34mLinux\033[00m"

However, when I incorporate the escape codes into my PS1 prompt variable, they are not being escaped. What do I need to do to get a colored prompt? Besides being something of a sucker for eyecandy, I find that a colored prompt is useful when visually parsing output.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Just use a literal Esc character, entered with Ctrl-v,Esc (will be displayed as ^[ on the screen):

PS1="^[[34mLinux^[[00m"

Or use the output of the echo command you find out is working:

PS1="$(echo -e "\033[35mLinux\033[00m")"
share|improve this answer
    
It's at times like this that I realize I am yet a commandline noob. I usually feel so good in comparison to my friends. :) The first version worked nicely; what a neat trick! I didn't have success with the second version. +1 –  Kazark Jul 5 '12 at 18:57
add comment

You need to put a literal escape character in the PS1 variable. Ksh88 and clones such as pdksh and mksh (older versions) have no literal syntax for control characters except through the print built-in. Mksh understands \e for escape, but pdksh requires the octal code \033.

PS1=$(print '\033[34mLinux\033[00m')

ATT ksh93 introduces the backlash-escaped literal syntax $'…' (also available in mksh since R39b). You can use backslash escapes to put control characters in these literals.

PS1=$'\e[34mLinux\e[00m'
share|improve this answer
    
Actually, mksh also supports $'…' – admittedly because Dave Korn (the Korn in Korn Shell) insisted I add it. –  mirabilos Feb 27 at 14:01
    
@mirabilos Ah, thanks. I probably typed that answer on a machine with mksh R39 and didn't check newer versions. –  Gilles Feb 27 at 14:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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