Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using:

red=$(tput setaf 1) 
green=$(tput setaf 2)
blue=$(tput setaf 4)
reset=$(tput sgr0)
export PS1="\[$red\]\u\[$reset\]@\[$green\]\h\[$reset\]:\[$blue\]\w\[$reset\]\$ "
export EDITOR=nano

This is what shows: []\u[]@[]\h[]:[]\w[]$

How can I fix this? Seems like bash does not interprete the special characters.

share|improve this question
    
Which terminal are you using here? –  Paŭlo Ebermann Jul 4 '11 at 0:39
    
Nice use of variables! It works for me. What's the output of echo $TERM for you? –  Aleksandr Levchuk Jul 4 '11 at 1:40
    
Are you sure you're running bash? Where did you put these lines? They should be in ~/.bashrc and you shouldn't export PS1, which is a shell setting and not an environment variable. If the lines aren't in .bashrc, put them there and read this. –  Gilles Jul 4 '11 at 6:52
    
echo $TERM shows xterm-color. Does the same on another system I have where it works, so I think that should be good. Removed the export, no success :). Thx for the link, good read. –  Hendrik Jul 4 '11 at 13:52
    
Now echo $PS1 shows me :" $ ". I previously logged in as root, then switched to another user. Now, when logging in via that user directly it shows no $PS1. Also, trying to autocomplete does not work, as well as pressing the arrow keys. –  Hendrik Jul 7 '11 at 8:36

2 Answers 2

Solution:

The users were using /bin/sh not /bin/bash

Changing this resolved all the issues I had.

share|improve this answer

The fact that, in your example output, the shell prompt still has the square brackets and escapes suggests that something's a bit screwy with your quoting locally, but what you pasted in your question does work for me in a simple cut-n-paste using bash 4.1.5(1)-release.

share|improve this answer
    
Now using: red=$(tput setaf 1) green=$(tput setaf 2) blue=$(tput setaf 4) reset=$(tput sgr0) color=$("[$red]\u[$reset]@[$green]\h[$reset]:[$blue]\w[$reset]\$ ") PS1="$color" export EDITOR=nano Does not help. It works on all my other systems, how can I check my 4.1.5 release? –  Hendrik Jul 4 '11 at 13:53

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.