Echo is an internal command of the shell that prints the specified string on the screen. Command format:
You can use echo to achieve more complex output format control.
Show escape characters
echo "\" It is a test\ ""
The result will be:
Double quotes can also be omitted.
Show Variables
Name= "OK" echo "$name It is a test"
The result will be:
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:
Show line breaks
echo "ok!\n" echo "It is a test"
Output:
show No line breaks
echo "Ok!\c" echo "It is a test"
Output:
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:
Show command execution results
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