I have no colors in my terminal on KDE Kubuntu 16.04.1.

Here it doesn't work

here is my .bashrc (I copied it from an Ubuntu-Server 16.04.1 but I always used this one also on former KUbuntu 12.04.)

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.                                                                                                                     
shopt -s checkwinsize                                                                                                                                         

# If set, the pattern "**" used in a pathname expansion context will                                                                                          
# match all files and zero or more directories and subdirectories.                                                                                            
#shopt -s globstar                                                                                                                                            

# make less more friendly for non-text input files, see lesspipe(1)                                                                                           
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"                                                                                                  

# set variable identifying the chroot you work in (used in the prompt below)                                                                                  
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then                                                                                             
    debian_chroot=$(cat /etc/debian_chroot)                                                                                                                   

# set a fancy prompt (non-color, unless we know we "want" color)                                                                                              
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\]\u\[\] @ \[\]\h\[\]:\[\]\w\[\]$ '
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$ '
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s‍/;s/[;&|]\s*alert$                                  //'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion

I also tried this and this but I have no color in terminal nor via ssh though

> echo $TERM

Anyway the colored output of apt update or ls -a e.g. works

la works to so color in general works

only not the prompt which I would expect to look like on the other server where I copied the .bashrc from and where it is working:

Here it works

Is there something I'm missing? How can I get the colored prompt working? (Especially asking because I want my green and the root's red but none of both work)

  • What if you remove the conditional and just set the colored PS1? If you get a colored PS1 in that way, it means somehow the conditional doesn't work for you. – AlvaroGMJ Sep 21 '17 at 13:36
  • @AlvaroGMJ Thanks for your help. As John Smith already pointed out I copied the script the wrong way into the server so that PS1 never was set correctly – derHugo Sep 22 '17 at 17:26

I may be wrong, but I do not see any color-related syntax in your script

PS1='${debian_chroot:+($debian_chroot)}\[\]\u\[\] @ \[\]\h\[\]:\[\]\w\[\]$ '

When I call your code from my bash prompt

PS1='\[\]\u\[\] @ \[\]\h\[\]:\[\]\w\[\]$ '

I see just white letters. You do not even have export PS1, which means that this variable never affects anything outside the script. My guess is that on your old machine some other script was responsible for colors.

In order to get the colors, which you have posted, try to call the following from your terminal

PS1='\[\033[1;32m\]\u\[\033[0m\] @ \[\033[0;32m\]\h\[\033[0m\]:\[\033[31m\]\W\[\033[0m\]\$ '

if it works, put

export PS1='\[\033[1;32m\]\u\[\033[0m\] @ \[\033[0;32m\]\h\[\033[0m\]:\[\033[31m\]\W\[\033[0m\]\$ '

into your ~/.bashrc.

  • A big huge facepalm here on my side :D ... What I did: I used cat .bashrc on the one server and copy pasted the output to the other server... What happened: Ofcourse (stupid me) when I did cat .bashrc the code e.g. }\[^[[01;32m\]\u\[^[[00m\] got printed out as a fad green string like \]\u\[ :D :D didn't notice that line when I just copied the whole output of cat. – derHugo Sep 21 '17 at 16:33
  • no problem, similar things happened to me too on numerous occasions) thanks for marking my answer. but in future better use scp or rsync for moving files between servers. – John Smith Sep 21 '17 at 16:39
  • yeah I usually use those or sometimes even nano .. but this time I wanted to be fast ... :P turned out to be slower than the usual :D – derHugo Sep 21 '17 at 16:45

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.