User Tools

Site Tools


bash_color

If you want to send us your comments, please do so. Thanks
More on comments


Bash colors and cursor movements

Show what the terminal is capable of: msgcat --color=test

You can show what terminal you have with echo $TERM
When used with echo use echo -e
tput can also be used

CodeExplanation
\eCode for the escape character. See also \033 (octal)
\nNew line
\rMove to the beginning of the line
\tTab
\vVertical tab
\033C-style octal code for the escape character
\x1Bhex code for the escape character
[9DMoves the cursor back 9 columns
[2KErases the current line
echo -e “\e[20A”Moves the cursor 20 lines up
echo -e “\e[20F”Moves the cursor 20 lines up and to position 1
echo -e “\eD”Linefeed
\e[CSI Control sequence introducer
\x9BCSI. Is equivalent to “ESC [”. Does not seem to work in bash

Syntax

The default syntax

echo -e "\033[MODIFIER;BACKGROUND;FOREGROUNDmTEXT\033[00m"

See Colors for more ways

Colors

A line with a new line and colored text can be made with

echo -e "\e[32mGreen text on the default background\e[0m"
echo -e "\n\033[01;44;37mWhite bold text on a blue background\033[00m"
echo -e '\n\e[32;40m'"\e[1mGreen bold text on a black background color\e[0m"
for i in {0..255}; do printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n"; done


Foreground colors
For background colors replace the leading 3 with a 4

ColorCodeLight colorCode
Black0;30Dark Gray1;30
Red0;31Light Red1;31
Green0;32Light Green1;32
Brown0;33Yellow1;33
Blue0;34Light Blue1;34
Magenta0;35Light Magenta1;35
Cyan0;36Light Cyan1;36
Light Gray0;37White1;37

Show them (the echo statement makes a new ling)

printf '\e[%sm ' {40..47} 0; echo

Modifiers

ModifierEffectRemark
\e[0mDefaultColor off
\e[1mBold
\e[2mHalf intensity
\e[3mItalic
\e[4mUnderline
\e[5mBlink
\e[6mNormal
\e[7mInverted
\e[8mHidden
\e[9mStrike trough

Parameters

Parameters are used in 24 bit color schemes. In

echo -e "\e[48;2;128;34;177m"

the '2' is the parameter

ParameterExplanation
0Defined by the implementation
1Transparent
2Red Green Blue (optional). This is used in 24 bit color schemes. Example: ESC[48;2;128;34;177m Sets the background color. Command:
echo -e "\e[48;2;128;34;177m"
3Cyan Magenta Yellow (optional)
4Cyan Magenta Yellow Black (optional)
50-255 indexed color. This is used in 8 bit color schemes. Example: ESC[48;5;177m Sets the background color and underlines. Command:
echo -e "\e[48;5;177m\e[4m"
6
7
8
9

tput

tput, reset - initialize a terminal or query terminfo database
tput is an interface to the terminfo library

OptionFunction
cup x yMove the cursor to position x,y
clearEcho the clear-screen sequence for the current terminal
colsPrint the number of columns for the current terminal
rcRestores the cursor where tput sc was called
scSaves the current cursor position

Info

man console_codes - Linux console escape and control sequences
man termcap - terminal capability database
man terminfo - terminal capability data base

VT ANSI
ANSI Escape Sequences Chapter 6: Colours and Cursor Movement:
6.1. Colours
6.2. Cursor Movement
and
All-escapes
ANSI escape code on Wikipedia
Bash tip colors and formatting
Terminalcodes
man 4 console codes

tput
Bash Prompt customization
Colours and Cursor Movement With tput
Discover tput


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
bash_color.txt · Last modified: 15-11-2021 22:06 by wim