In the shell of Linux, echo changes the output display style

Source: Internet
Author: User
Tags control characters echo command


In the shell of Linux, echo changes the output display style echo-e "\033[32;49;1m [done] \033[39;49;0m" or echo-e "\e[32;49;1m [done] \033[39;49;0m"

Output result: [Done]


The color of the text terminal can be generated by using the ANSI unconventional character sequence. Example:

Echo-e "\033[44;37;5m ME \033[0m COOL"

The above command sets the background to blue, foreground white, blinking cursor, output character "ME", then reset screen to default settings, output character "COOL". "E" is an optional option for the command echo, which is used to activate the parser for special characters. "\033" guides the non-regular character sequence. "M" means to set the property and then end the unconventional character sequence, the real valid characters in this example are "44;37;5" and "0".

modifying "44;37;5" can produce combinations of different colors, which are not related to the sequence of values and encodings. The encoding you can choose is as follows:

Coded Color/action
0 Reset properties to default settings
1 setting Bold
2 Set half brightness (simulates color of color display)
4 Set underline (simulates color of color display)
5 Setting flashes
7 Setting the reverse image
22 Setting general Density
24 Turn underline off
25 Flashing off
27 Turn off reverse image
30 setting Black foreground
31 set Red foreground
32 Setting Green foreground
33 Setting Brown foreground
34 Set Blue Foreground
35 Setting Purple foreground
36 Setting the Cyan foreground
37 Setting White foreground
38 underline on the default foreground color
39 Turn the underline off on the default foreground color
40 Setting a black background
41 Setting the red background
42 Setting the green background
43 Setting the brown background
44 Setting the blue background
45 Setting purple Background
46 Setting the Cyan background
47 Setting a white background
49 Setting the default black background


Other interesting codes are:

\033[2J Clear the screen
\033[0q Turn off all keyboard LEDs
\033[1q Setting the "SCROLL Lock" indicator (Scroll Lock)
\033[2q Setting the value Lock indicator (Num lock)
\033[3q Setting the CAP Lock indicator (CAPS LOCK)
\033[15:40h move off to line 15th, column 40
\007 beep of the hair bee

#######################

How to change the font and background color of Redhat:

Command:
Ps1= "[\e[32;1m\[email protected]\h \w]\\$"
Or
Export ps1= "[\e[32;1m\[email protected]\h \w]\\$" The difference between the two see the relevant information about the environment variables

Explain:

\e[32;1m: This is the escape character that controls the font and background color, 30~37 is the font color, 40~47 is the background color

Example of the position of the 32;1m number can be swapped, such as \e[1;32m, if it is in the X environment can be replaced 1 of the range 0~10, there may be no use: 0 or do not write (\e [0;32m or \e[;32m) display light color, 1: Display highlighting 4: underline ... If the effect is not good, but can not be restored, then do not write the number in front of M, such as \e[32;m, or directly logout and landing

\u \h \w: Here are some escape characters, explained in detail below:

\d: Represents the date, formatted as weekday month date, for example: "Mon-1"

\h: The full host name. For example: My machine name is: Fc4.linux, then this name is Fc4.linux

\h: Only the first name of the host is taken, as in the example above, then Fc4,.linux is omitted

\ t: Display time in 24-hour format such as: HH:MM:SS

\ t: Display time in 12-hour format

\a: Display time in 24-hour format: hh:mm

\u: Current user's account name

Version information for \v:bash

\w: The full working directory name. Home directory will be replaced by ~

\w: Use basename to get the working directory name, so only the last directory is listed

\#: The first few commands issued

\$: Prompt character, if root, Prompt is: #, normal user is: $

\ n: Create a new row

The font is not limited to one color and can have multiple colors:
Ps1= "[\e[32;1m\[email protected]\e[35;1m\h \e[31;1m\w]\\$"

The above two commands after logging off and then landing on the invalid, the following method to make it permanent effect:
Vi/etc/profile
Add a line under "Export PATH ...": Export ps1= "[\e[32;1m\[email protected]\h \w]\\$"
Log out and then log in, it succeeds, if not effective, use the Source/etc/profile command to try, or directly restart the machine.

********************************************************************

Sometimes, you need to cut a map for the configuration of the Linux service, and then print out, the results in the character interface is only a black background, white font, printing ink ~ ~ Change the background may be better.

The first thing to know in Linux, some common color code: (These colors are ANSI standard colors)
Foreground: 30 Black 31 Red 32 green 33 yellow 34 Blue 35 violet 36 Cyan 37 White
Background color: 40 Black 41 red 42 green 43 yellow 44 blue 45 violet 46 Green 47 White
# foreground color each number is corresponding to the background color minus 10.

Command: Echo-e "\033[background_number;foreground_numberm"
If setting white background black foreground font should be Echo-e "\033[47;30m"

background_number= background Color
foreground_number= Front View
M to follow Foreground_number, no spaces.

(said to be white background, black font.) Font Color I agree, but the background color does not look like white? O (∩_∩) o ... )

\033 is the ASCII code (27) that exits the key <esc>, so the above command can also be written in the following form
echo "^[[47;30m" where the "^[" is the first to press CTRL-V, and then press <esc> (which is the key in the upper left corner of the keyboard) produced.

This method can only be changed for a while, logout a little bit. But you can vi/root/.bashrc, and add the order just after.

Echo-e ' \033[47;30m '

************************************************************************

Using the terminal control characters, such as this, the cursor jumps to the 60th column, and then displays an OK

Echo-en ' \033[60g ' && echo OK

\033[is the terminal escape character beginning, 60G is the command.
Echo's-e option is to let echo not handle the terminal escape character in the built-in command echo output his parameters, separated by a space, ending with a newline character. The return value is always 0. Some of the options that Echo uses are:-E: Escape backslash characters.
-N: No line break.


Escape sequences used by the echo command


Sequence meaning
\a Alarm
\b Backspace
\c Force line break
\e exit
\f Clear the screen
\ n New Line
\ r Carriage return.
\ t Horizontal tab
\v Vertical Tab
\ \ counter Slash


$ #The number of parameters passed to the script



$* parameters passed to the script, unlike positional variables, this option parameter can exceed 9



$$ the current process ID number of the script runtime, often used as a suffix for temporary variables. such as hash.$$



$! background Run & last process ID number



[email protected] with $ #same, use quotation marks, and return the number of arguments in quotation marks



$-last parameter of previous command



$? The launch status of the final command, 0 means no error. Any other value indicates an error.


Detect languageAfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutch中文版EsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutch中文版EsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu
Text-to-Speech function is limited to characters Options:History:Help:Feedback


In the shell of Linux, echo changes the output display style


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.