echo

Display a line of text.

Syntax

echo [SHORT-OPTION]... [STRING]...
echo LONG-OPTION

Description

Echo the STRING(s) to standard output.

Options

-n     do not output the trailing newline

-e     enable interpretation of backslash escapes

-E     disable interpretation of backslash escapes (default)

Escape Sequence

If -e is in effect, the following sequences are recognized:

       \\     backslash

       \a     alert (BEL)

       \b     backspace

       \c     produce no further output

       \e     escape

       \f     form feed

       \n     new line

       \r     carriage return

       \t     horizontal tab

       \v     vertical tab

       \0NNN  byte with octal value NNN (1 to 3 digits)

       \xHH   byte with hexadecimal value HH (1 to 2 digits)

Fonts Properties

echo command can change font style, background color of fonts and font colors. Escape sequence \033 can be used to alter font properties. -e option has to be used in order to the escape sequence be in effect. Various escape codes are as follows:

  • [0m: Normal
  • [1m: Bold fonts
  • [2m: Font color changes to Purple
  • [4m: Underlined fonts
  • [7m: Invert foreground and background colors
  • [8m: Invisible fonts
  • [9m: Cross lined fonts
  • [30m: Font color changes to Grey
  • [31m: Font color changes to Red
  • [32m: Font color changes to Green
  • [33m: Font color changes to Brown
  • [34m: Font color changes to Blue
  • [35m: Font color changes to Violet
  • [36m: Font color changes to Sky Blue
  • [37m: Font color changes to Light Grey
  • [38m: Font color changes to Black
  • [40m: Background color changes to Black
  • [41m: Background color changes to Red
  • [42m: Background color changes to Green
  • [43m: Background color changes to Brown
  • [44m: Background color changes to Blue
  • [45m: Background color changes to Violet
  • [46m: Background color changes to Sky Blue
  • [47m: Background color changes to Light Grey

Example: 1

echo -e "\033[31mHello Visitor\033[0m" The above command would print "Hello Visitor" in red color.

Example: 2

echo -e "\033[1m\033[41mHello Visitor\033[0m" The above command would print "Hello Visitor" in bold style and red background color.

Example 1

Display a string on standard output.

[eleiss@eleiss ~]$ echo "Eleiss Linux Resources"
Eleiss Linux Resources
[eleiss@eleiss ~]$

Echo prints the string given as argument on standard output.

Example 2

Demonstrate escape sequences in echo command.

[eleiss@eleiss ~]$ echo -e "Eleiss\vLinux\vResources"
Eleiss
      Linux
           Resources
[eleiss@eleiss ~]$

Escape sequences can be used to format the output on standard output.

Example 3

Print a variable's value on standard output using echo command.

[eleiss@eleiss ~]$ os=Linux
[eleiss@eleiss ~]$ echo "I use $os"
I use Linux
[eleiss@eleiss ~]$

A variable "OS" has been assigned value "Linux" which is accessed by preceding a "$" sign to the variable name.

Example 4

Testing echo command ( To be deleted )

[nicks@patroclus ~]$ echo "time pass"
time pass
[nicks@patroclus ~]$
This is a time pass example. Do not forget to delete it.

You may write to resources@eleiss.com for any Linux related queries.

advertisement