Linux echo Command Details

Source: Internet
Author: User
Tags echo command

The echo command for Linux, which is very common in shell programming, is often used when printing variable value under a terminal, so it is necessary to understand the use of Echo

The function of the echo command is to display a piece of text on the display, which generally acts as a hint.
The general format of the command is: Echo [-n] String
where option n means that the output text is not wrapped, the string can be quoted, or it can be unquoted. When you output a quoted string with the Echo command, the string is output as it is, and when you output an unquoted string with the echo command, each word in the string is output as a string, separated by a space between the strings.

Feature Description: Displays text.
Syntax: Echo [-ne][string] or echo [--help][--version]
Additional note: Echo will send the input string to standard output. The output strings are separated by white space characters, and a newline number is added at the end.
Parameter:-n do not wrap in the last line
-E If the following characters appear in the string, they are handled in particular, not as a general
Text output:
\a issued a warning sound;
\b Delete the previous character;
\c finally not add the line break symbol;
\f the line but the cursor remains in its original position;
\ n Wraps and the cursor moves to the beginning of the line;
\ r The cursor moves to the beginning of the line, but does not wrap;
\ t Insert tab;
\v is the same as \f;
\ \ insert \ character;
\NNN inserts the ASCII character represented by the NNN (octal);
Help Display Help
–version displaying version information

Grammar:
    1. # echo [Options] [String]

The items in square brackets are optional. A string can be defined as a finite sequence of characters (such as letters, numbers, symbols, punctuation marks).

When the echo command is used without any options or strings, it returns a blank line on the display, followed by a line followed by a command prompt. This is because pressing the ENTER key sends a signal to the system to start a new line, and Echo repeats the signal.

Options:
    • -n Do not output new lines derived
    • -e enable backslash escape interpretation
    • -E Disables Backslash escape interpretation (default)

If you use the-e option, you can use the following escape sequence:

    • \ Backslash
    • \a Warning (BEL)
    • \b Reverse Slash
    • \c does not produce further output
    • \e Escape
    • \f Page Change
    • \ n New Line
    • \ r newline Character
    • \ t Horizontal Tabulation
    • \v Vertical Tabulation
    • \0nnn octal value represents the byte nnn (1 to 3 digits)
    • \XHH hexadecimal value represents the byte nnn (1 to 2 digits)
10 Linux interview questions and answers for different scenarios http://www.linuxidc.com/Linux/2014-04/99710.htm

10 Core Linux interview questions and Answers http://www.linuxidc.com/Linux/2014-04/100447.htm

Example: 1 Displays the value of a system-defined variable

Using the SET command, we can list the system-defined variables. To print the values of these variables, we can use the echo command:

    1. [Email protected] : ~$ echo $USER
    2. Jack
    3. [Email protected] : ~$ echo $HOME
    4. /Home/Jack
Example: 2 Displays the value of a user-defined variable
    1. [Email protected] : ~$ var1=' Date '
    2. [Email protected] : ~$ echo "Today ' s date time is: $var 1"
    3. Today'sdate time Is:mon Jul 13:11:37 IST
Example: 3 displaying a text string
    1. [Email protected] : ~$ echo "Hi this echo command testing"
    2. HiThis echo command testing
Example: 4 using a backslash in the echo command
    1. [Email protected] : ~$ echo -e "Ubuntu \bis \bthe \bbest \bdesktop \bos"

The above command will print:

Ubuntuisthebestdesktopos

Example: 5 using tab spaces in the Echo command
    1. [Email protected] : ~$ echo -e "Ubuntu \tis \tthe \tbest \tdesktop \tos"

The above command displays the following output:

Ubuntu is the best Desktop OS

Example: 6 Using the Vertical tab in the Echo command
    1. [Email protected] : ~$ echo -e "Ubuntu \vis \vthe \vbest \vdesktop \vos"
    2. Ubuntu
    3. Is
    4. The
    5. Best
    6. Desktop
    7. OS
Example: 7 Setting the echo command color output

The echo command can modify font type, font background color, and font color, and escape sequence \033 can be used to change font properties. For the escape sequence to take effect, you must use the-e option. A partial escape code is listed below:

    • [0m: Normal
    • [1m: Bold
    • [4m: Font plus underline
    • [7m: Reverse foreground and background color
    • [8m: Invisible characters
    • [9m: Cross-line font
    • [30m: Gray font
    • [31m: Red font
    • [32m: Green Font
    • [33m: Brown font
    • [34m: Blue Font
    • [35m: Purple Font
    • [36m: Light blue Font
    • [37m: Light gray font
    • [38m: Black Font
    • [40m: Black background
    • [41m: Red background
    • [42m: Green background
    • [43m: Brown background
    • [44m: Blue background
    • [45m: Purple background
    • [46m: Light blue background
    • [47m: Light gray background

The following command prints the output in red.

    1. [Email protected] : ~$ echo -e "\033[31mmagic of linux\033[0m"
    2. Magic of Linux

The following command prints "Magic of Linux" in bold and red backgrounds.

    1. [Email protected] : ~$ echo -e "\033[1m\033[41mmagic of linux\033[0m"
    2. Magic of Linux

Use Echo to print color fonts and color backgrounds under shell http://www.linuxidc.com/Linux/2014-07/104776.htm

Linux Command Terminal print-echo http://www.linuxidc.com/Linux/2014-04/99571.htm

15 ' echo ' command instances in Linux http://www.linuxidc.com/Linux/2014-10/107550.htm

This article permanently updates the link address : http://www.linuxidc.com/Linux/2014-08/105548.htm

Linux echo Command Details

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.