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

3 Answers 3

up vote 8 down vote accepted

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


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

I use these in mkshfor a user shell:

# custom prompt see http://comments.gmane.org/gmane.os.miros.mksh/126
PS1=$'\a\r\a\e[1;34m\a ^ ^  ^ ^ | \a\e[36m\a${USER:=$(ulimit -c 0; id -un 2>/dev/null || echo
\?)}@${HOSTNAME%%.*}\a\e[34m\a | ^ ^  ^ ^ | \a\e[0;33m\a$(local d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~};
print -nr -- "$d")\a\e[1;34m\a |\n ^ ^  ^ ^ | \a\e[32m\a$(date +%H:%M)\a\e[34m\a | ^ ^ >>\a\e[0m\a '

& a slightly different shell for root:

PS1=$'\a\r\a\e[1;34m\a ^ ^  ^ ^  ^   \a\e[31m\a${USER:=$(ulimit -c 0; \
    id -un 2>/dev/null || echo \?)}@${HOSTNAME%%.*}\a\e[34m\a  ^ ^  ^ ^  ^ ^  ^   \a\e[0;33m\a$(
        local d=${PWD:-?} p=~
        [[ $p = ?(*/) ]] || d=${d/#$p/~}
        print -nr -- "$d"
)\a\e[1;34m\a  ^ ^ \n ^ ^  ^ ^  ^   \a\e[32m\a$(date +%H:%M)\a\e[34m\a  ^ ^  ^ ^   \a\e[0m\a '

enter image description here

share|improve this answer

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.

share|improve this answer
Actually, mksh also supports $'…' – admittedly because Dave Korn (the Korn in Korn Shell) insisted I add it. –  mirabilos Feb 27 '14 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 '14 at 14:09

Your Answer


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.