# bash - problem when using ANSI/color codes in PS1



## jarek6 (Mar 22, 2016)

Hi
I have problem with Bash when I using ANSI codes in PS1 env variable (prompt). For example with terminal width is = 80 (COLUMNS=80) if command line plus prompt reach 76 characters next character is printed in same line at it's beginning. Normal behavior is that command line have to reach full width (80 characters in this example) and then 81 will be printed in next line.
It's not problem of terminal (Putty) as I also have this issue from console (vty).


```
~$ pkg info | grep bash
bash-4.3.42_1                  The GNU Project's Bourne Again SHell
```

Did anyone have same problem ? On older FreeBSD (7.x and 8.x) with bash-3.0.16_1 I don't have this issue at all.


----------



## aragats (Mar 22, 2016)

Just use 
	
	



```
\[\e[0m\]
```
it works correctly.

I've created a file which I source in my .bashrc to make life easier:

```
Black='\[\e[0;30m\]'
DarkGray='\[\e[1;30m\]'
Blue='\[\e[0;34m\]'
LightBlue='\[\033[1;34m\]'
Green='\[\e[0;32m\]'
LightGreen='\[\e[1;32m\]'
Cyan='\[\e[0;36m\]'
LightCyan='\[\e[1;36m\]'
Red='\[\e[0;31m\]'  
LightRed='\[\e[1;31m\]'
Purple='\[\e[0;35m\]'
LightPurple='\[\e[1;35m\]'
Brown='\[\e[0;33m\]'  
Yellow='\[\e[1;33m\]'
LightGray='\[\e[0;37m\]'  
White='\[\e[1;37m\]'
NoColor='\[\e[0m\]'
```


----------



## zirias@ (Mar 23, 2016)

aragats said:


> I've created a file which I source in my .bashrc to make life easier:
> 
> ```
> Black='\[\e[0;30m\]'
> ...



As an alternative, you can use tput(1):

```
Black=`tput setaf 0`
Red=`tput setaf 1`
[...]
```
The capability name for background color is `setab`. Advantages of this approach are a better readability as well as compatibility with more "exotic" terminals.


----------

