Linux Command memo instance (1) -- terminal output, linux memo

Source: Internet
Author: User

Linux Command memo instance (1) -- terminal output, linux memo

A terminal is a window for the user to interact with the shell environment. Most of the interaction results of all commands are directly displayed to the user from the terminal. Therefore, this part is the basis for friendly display of results.

1. Command Overview

Echo is a basic terminal output command that directly inputs input parameters. The command format is as follows:

echo [options] toBeOutput

Details are as follows:

2. Features and instance description1. line feed

By default, a line break is added after each call. Use the-n option to remove this default value.

User @ ubuntu :~ $ Echo test a line
User @ ubuntu :~ $ Test a line
User @ ubuntu :~ $ Echo-n test a line
Test a line user @ ubuntu :~ $

2. quotation marks

Echo parameters can be Output Using Double quotation marks, single quotation marks, and no quotation marks. Each method has its own features:

  • Double quotation marks can be used to parse the internal variable values, but cannot contain "!", This symbol has special significance. You can use "!". Escape, or use set + H before echo
  • Using single quotes, all content is printed as characters, that is, the internal variable value is not parsed and can contain "!".
  • Shell does not have delimiters when no quotation marks are used, so it cannot be used in the text. Although "!" Can be output, However, if ";" is contained in the shell, it is considered by shell to be multiple commands, resulting in an error.

User @ ubuntu :~ $ Var = world
User @ ubuntu :~ $ Echo welcome to shell, $ var
User @ ubuntu :~ $ Welcome to shell, world
User @ ubuntu :~ $ Echo "welcome to shell, $ var"
User @ ubuntu :~ $ Welcome to shell, world
User @ ubuntu :~ $ Echo 'Welcome to shell, $ var'
Welcome to shell $ var

User @ ubuntu :~ $ Echo welcome; hello world
Welcome
Hello: command not found
User @ ubuntu :~ $ Echo "welcome! Hello world ."
Bash :! Hello: event not found
User @ ubuntu :~ $ Echo "welcome! Hello world ."
Welcome! Hello world.
User @ ubuntu :~ $ Echo 'Welcome! Hello world .'
Welcome! Hello world.
User @ ubuntu :~ $ Echo welcome! Hello world.
Welcome! Hello world.

3. Escape

Echo's-e Option supports escaping strings in double quotation marks:

Echo-e "string containing escape sequences"

The Escape Character details list all transfer character formats.
The-E option can be used to explicitly remove escape characters and output all characters as they are. The default option is not to use escape characters.

User @ ubuntu :~ $ Echo-e "\ t"

User @ ubuntu :~ $ Echo "\ t"
\ T
User @ ubuntu :~ $ Echo-E "\ t"
\ T

4. Color output

Escape Sequence for color. Text color: reset = 0, black = 30, Red = 31, Green = 32, yellow = 33, Blue = 34, Magenta = 35, cyan = 36, white = 37.
Background Color: reset = 0, black = 40, Red = 41, Green = 42, yellow = 43, Blue = 44, Magenta = 45, cyan = 46, white = 47.

User @ ubuntu :~ $ Echo-e "\ e [1: 42 m green background \ e [0 m"

5. Expansion

Printf can also be used for terminal output. The parameters and formats used are similar to those in C. You can specify the format string, the width of the string, and the left-right alignment. Line breaks are not added by default.

User @ ubuntu :~ $ Printf '%-5 s %-10 s %-4.2f \ n' Num James 80.324
Num James 80.32

"-" Indicates alignment to the left, which is aligned to the right by default ." 4.2 "indicates that it occupies 4 characters in width and retains two decimal places ." S/f/c "and other placeholders indicate types.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.