Colored Prompt in KornShell

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")"

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'

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

As the special characters did not copy, here is a pastebin paste for both the normal user and root.

Tags:

Colors

Ksh

Prompt