one echo command output text
1.1 displaying normal strings
echo [Options] string
option means that the command option, only-n, does not output a newline character at the end of the line.
If the text you want to output is made up of multiple lists, enclose it in double quotation marks.
Echo-n "What's your first name?" 1.2 Show escape characters
To use the echo command to support escape characters, use the-e option.
\b Backspace
Echo-e "This is a\b string" (output this is string)
\c suppress continuation of output text
Echo-e "Hello \c world." (Output Hello)
\ r return character
\ n line break
1.3 Display variables
The Echo statement prints the value of a variable in the program, and you can use {} to define the variable name.
Echo-n "Please input a name:"
Read name
#输出变量的值
echo "Hello, $name"
v1= "Sing"
V2= "Danc"
#错误的输出变量值的方法
echo "We are $v 1ing and we are $v 2ing."
(Correct echo "We are ${v1}ing, we are ${v2}ing.") 1.4 Show Command execution results
Echo can display the results of the execution of the shell command, using the anti-quote "' to bring the command.
echo ' command ' 1.5 echo command execution result redirection
Redirection is the standard output of a shell command that is redefined to a file. By default, the standard output device for the echo command is a monitor, and sometimes the information displayed by the echo command is saved to a disk file. Redirect is now necessary.
The redirected operator is > or >>, and in the case of the target file, the former overwrites the original contents of the destination file, which appends the data to the end of the original file.
#将要输出的信息写入文件, it will overwrite
echo "Hello,world." > Hello.txt
#将输出的信息追加到文件的结尾, will not overwrite
echo "Hello,chunxiao." >> hello.txt