0

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.

5
  • Which terminal are you using here? Jul 4, 2011 at 0:39
  • Nice use of variables! It works for me. What's the output of echo $TERM for you? Jul 4, 2011 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. Jul 4, 2011 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, 2011 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, 2011 at 8:36

2 Answers 2

1

Solution:

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

Changing this resolved all the issues I had.

0

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.

1
  • 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, 2011 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .