ECHO is an internal instruction of the shell to print out the specified string on the screen. Command format:
Copy Code code as follows:
You can use echo to achieve more complex output format control.
Show escape characters
Copy Code code as follows:
echo "\" It is a test\ ""
The result will be:
"It is a test"
Double quotes can also be omitted.
Show variables
Copy Code code as follows:
Name= "OK"
echo "$name It is a test"
The result will be:
OK It is a test
The same double quotation marks can also be omitted.
You need to use curly braces ({}) if the variable is connected to another character:
Copy Code code as follows:
Mouth=8
echo "${mouth}-1-2009"
The result will be:
8-1-2009
Show Line Wrapping
Copy Code code as follows:
echo "ok!\n"
echo "It is a test"
Output:
Ok!
It is a test
Show No Line wrapping
Copy Code code as follows:
echo "Ok!\c"
echo "It is a test"
Output:
Ok! It si a test
Show results directed to file
Copy Code code as follows:
echo "It is a test" > myfile
Output string AS-is
Use single quotes if you want to output strings as they are (without escaping). For example:
Copy Code code as follows:
Show Command Execution results
Copy Code code as follows:
The result displays the current date
As you can see from the above, double quotes are dispensable, and single quotes are mainly used in the original output.