Shell Learning--terminal printing

Source: Internet
Author: User

1. Echo
1.1, by default, Echo adds a line break after each call
1.2, the content to be printed, you can use single quotation marks, double quotation marks or direct printing, different ways, have their own restrictions
1.2.1, using the non-quoted Echo, can not print well (;), because the semicolon in the bash shell used as the command delimiter
[Email protected] ~]# echo Hello world;
Hello World
[Email protected] ~]# echo ' Hello World; '
Hello world;
[Email protected] ~]#
1.2.2, special characters when printing with double quotation marks, you need to add an escape character
[Email protected] ~]# echo Hello world!
Hello World!
[Email protected] ~]# echo ' Hello world! '
Hello World!
[Email protected] ~]# echo "Hello World!"
echo "Hello World", "Logger": "Me.ele.acct.comm.biz.aop.MethodInvokeSection", "Sdatetime": "2018-08-17 14:07:53.075", "datetime": "1534486073076", "Docker_pid": "22720", "host": "xg-mesos-895", "Subappid": "", "app_id": " Me.ele.acct.server "," seq ":" 153448607307611392
>
> ^c
[Email protected] ~]#
1.2.3, variable substitution is not valid in single quotation marks
[Email protected] ~]# Name=jack
[Email protected] ~]# echo $name
Jack
[Email protected] ~]# echo "$name"
Jack
[Email protected] ~]# echo ' $name '
$name
1.3,-n option ignores end line break
[Email protected] ~]# echo-n Hello World
Hello World[[email protected] ~]#
1.4.-E option to print escape characters
[Email protected] ~]# echo-e "1\t2\t3"
1 2 3
[Email protected] ~]#
2. printf
2.1. printf uses reference text or parameters separated by spaces, and printf does not automatically add line breaks and needs to be added manually
[email protected] shell]$ cat printf.sh
#!/bin/bash
#file:p rintf.sh

printf "%-5s%-10s%-4s\n" No Name Mark
printf "%-5s%-10s%-4.2f\n" 1 Jack 80.3456
printf "%-5s%-10s%-4.2f\n" 2 Jeff 77.56
[Email protected] shell]$./printf.sh
No Name Mark
1 Jack 80.35
2 Jeff 77.56
[Email protected] shell]$
%s%c%d and%f are format substitutions, and the corresponding arguments are placed after the quoted format string
-Identify left-justified, right-justified by default

Shell Learning--terminal printing

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.