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