Shell Programming-Output (vi)

Source: Internet
Author: User

echo Output
echo instruction for the output of a string
Format: Echo string

Direct output String: string
Echo ' This is String-output '
In double quotes, you can also omit quotes here.

Escape character: \
echo ' \ ' It is ok\ '

Variable: \value
Echo ' \value It is value '

Line break: \ n
Echo-e ' This is \ n OK '
-E Open Escape

No newline: \c
Echo-e ' This is \c OK '

Results directed to file: >file
Echo ' This is file ' >file

Output a string as is, without escaping or taking variables: single quotes
Echo ' \name\ '

Command execution result: anti-quote '
Echo ' Date '

Single quotes cannot reference variables, transfer characters, and text formatting symbols (newline, tab)
Double quotes can refer to variables, transfer characters, and text formatting symbols (newline, tab)
No reference to variables, transfer characters, but not text format symbols (newline, tab)

printf output
printf uses reference text or space-delimited parameters, which can be used outside of the format string in printf, as well as the width of the string, left and right alignment, etc.

Format: printf format-string [parameter list]
printf "%d%s\n" "Test"
Here single quotes, double quotes, no quotation marks are possible

Escape sequences for printf
\a Warning Character
\b Back
\f Page Change
\ nthe line break
\ r Enter
\ t Horizontal tab
\v Vertical Tab
\ \ A literal backslash character
The \DDD represents a 1 to 3-digit octal value character. Valid only in format strings
\0DDD represents 1 to 3-bit octal value characters

printf format symbols
%d:decimal decimal Integer
%s:string string
%c:char characters
%f:float floating Point

printf Practice

%-10s refers to a width of 10 characters (-left aligned, no right-aligned) less than 10 characters are filled with spaces, and the contents are displayed in full

%-4.2F refers to the format of decimals, where. 2 means reserved 2 decimal places

Results:

Shell Programming-Output (vi)

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.