Echo is an internal command of the shell that prints the specified string on the screen. Command format:
Echo Arg
You can use echo to achieve more complex output format control.
Show escape characters
echo "\" It is a test\ ""
The result will be:
"It is a test"
Double quotes can also be omitted.
Show Variables
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.
If the variable is connected to another character, you need to use curly braces ({}):
Mouth=8echo "${mouth}-1-2009"
The result will be:
8-1-2009
Show line breaks
echo "ok!\n" echo "It is a test"
Output:
Ok! It is a test
show No line breaks
echo "Ok!\c" echo "It is a test"
Output:
Ok! It si a test
Show results redirected to file
echo "It is a test" > myfile
output String as-is
If you want to output the string as-is (without escaping), use single quotation marks. For example:
echo ' $name \ '
Show command execution results
Echo ' Date '
The result will show the current date
As can be seen from the above, double quotes are dispensable, single quotes are mainly used in the original output.
Shell Learning 13-shell echo Command