Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Note that I only want user's input to have specific color (words that user has typed with keyboard), not the actual command's output.

I tried:

export PS1="$ \033[38;5;154m"

I know that it should be closed with \033[m but I have no clue how to insert it after the input was sent to stdin.

export PS1="$ \033[38;5;154m$PS1\033[m"

This doesn't work either.

The reason why I want this is to be able to easily distinguish the input command from it's output. Thanks in advance.

share|improve this question
up vote 1 down vote accepted

Bash won't be able to color all user input. UNIX is full-duplex and all data displayed comes from the unix machine, not from the local terminal emulator/keyboard so the terminal emulator (xterm?) can't really tell the difference, and bash only controls what it does, not what every program does.

I use a different colored prompt.

if [[ "$EUID" -eq 0 ]]; then PC="$COLORred"; fi
PS1="\[$PC\]#===> \@ %\j / \u @ \h : \w/\n#===> \\\$ \[$COLORreset\]"

# Print when exit status is not 0 -- I like this too... shown in red
export PROMPT_COMMAND="x0=\$?;if ((\$x0 > 0)); then echo '${COLORred}# exit status = '\$x0' -- From PROMPT_COMMAND$COLORreset'; fi"

Maybe check

share|improve this answer

I've been working on this and a few other bash/terminal things all day, and figured I'd find any relevant questions and answer them if I could even be of any remote help -- so the below .bashrc will color the terminmal input command green and the output will be standard white. The background is still black.

# ~/.bashrc: executed by bash(1) for non-login shells.

# Created by EDH automated script to set up terminal colors
# Ref:
# Ref:
# Ref:
# Ref:

# Note: reload settings w/o relogin; source ~/.bashrc

# for terminal line coloring
export PS1="\[$(tput sgr0)\]\[$(tput setaf 1)\]\u \[$(tput setaf 6)\]\w \[$(tput setaf 1)\]\\$ \[$(tput setaf 2)\]"
none="$(tput sgr0)"
trap 'echo -ne "${none}"' DEBUG

# ls dir coloring
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'

I tried to include the sources where I found them! Hope this helps, even if this is an older thread.

share|improve this answer

I don't think you can get a different color for input commands and their output. In any case, you certainly cannot do this by setting the PS1 variable. The PS1 is the prompt, the text displayed to the left of whatever you type in. For example:

enter image description here

You can change the default colors of the terminal by modifying your .Xdefaults and/or .Xresources file. Have a look here, here and here for some more information.

share|improve this answer

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.