One of these is the venerable echo command. At first glance, this may seem like auseless command. Look under the hood, and you’ll find it to be surprisingly useful.
What Does ‘echo’ Do?
Look at the manual entry for echo, and you won’t find much help. It reads “displays a line of text.” This you could probably already infer from the name of the command. Basically, what echo does is send arguments to standard outputs along with a handful of basic formatting options. The main reason this command exists is to work inside other scripts, letting you show output to the person running the script.
The Basics
At a basic level, echo does exactly what it says it does. Here’s an example: That will print “Can anybody hear me.” If you just type the command, it literally looks like an echo, which is where the command gets its name. If you add a question mark to the above command, though, you’ll get an error. Type the following: The resulting text won’t have the quotes around it, but will properly display the question mark. You can also use variables with the echo command. The above command will print 256 to the terminal.
More Advanced Commands
The echo command works differently on certain systems. On Linux, for example, there are some options that you won’t find on other Unix-like operating systems. For example, the -e option allows you to insert characters like \n for newline or \t for tabs. It may look a little confusing at the end, but this will print something similar to the following: You can also use \b for backspace. Why you would want to delete a word you just carefully typed out may not make sense, but it does have the occasional use case.
Practical Examples
As already explained, the most practical use case for echo is in scripts you write. You can also use it do some slight cleanup for the output of other scripts. That said, for that use case there are many better tools for the job like grep and sed. Another great use case for echo is in slightly modifying configuration files. Just use the standard > redirect. As an example: This will append the text to the file “just-a-file.txt.” Run it again and the line will appear twice.
Conclusion
As you’re reading through these examples, you may find yourself wondering why anyone would ever use them. It could even have you second-guessing why anyone would ever want to use Linux instead of Windows or macOS. Usually, when something about Linux seems strange, it’s because it has its roots in how it was used decades ago. That doesn’t necessarily mean anything bad, though. If you’re not sure about Linux, take a look at our list of reasons you should learn to use Linux.