The echo command in Linux and Unix-like systems is used to display a line of text or a variable's value on the screen or in a file.
Here are a few examples of how the echo command can be used:
1. Display a line of text on the screen:
echo Hello, World!
2. Display the value of a variable:
This will display the value of the HOME environment variable)
2. Write text to a file:
echo Hello, World! > testworld.txt
The above will create a file named “testworld.txt” and write the text “Hello, World!” to it)
3. Append text to a file:
echo How are you? >> testworld.txt
The above will add the text “How are you?” to the end of the file “testworld.txt”. It's also possible to use the echo command to create a new line, by using echo -e with an escape sequence \n
echo -e "Hello\nWorld"
this will print “Hello” in a new line and “World” in next line
echo command is widely used in shell scripting and command line scripting, it's one of the most basic command and considered as one of the building blocks for more complex commands.