A Little About The ‘echo’ Command

That’s right, in today’s article we’re going to learn a little about the ‘echo’ command. We’ll barely be scratching the surface of the ‘echo’ command. There are so many ways to use ‘echo’ that we simply can’t fit it all into an article. Do, read on!

So, what is ‘echo’? Well, basically, the ‘echo’ command is a command that tells the computer to output text – be it in the terminal or using standard output to add that text to a file. It’s useful for regular people, but you’ll find it’s most commonly used in things like bash scripting

That sort of thing, scripting, is outside the scope of this article – and probably beyond the scope of the entire site. Maybe I’ll get to it, but those would end up being long articles, or articles written in parts. Besides, I’m not really all that good with scripting. (If you are good with scripting and would like to write some articles, do let me know.)

This is how the man page describes the ‘echo’ command:

echo – display a line of text

That’s indeed what it does. When you combine it with things like variables, you open up a whole new world. I don’t actually have a very good article about variables, other than existing variables. I should probably have said article.

Anyhow, we’ll just be scratching the surface of the ‘echo’ command. There are all sorts of ways to use ‘echo’, but we’re just going to use it in ways that a new Linux user might use it. Some basic familiarity is probably a good thing.

The ‘echo’ Command:

This article requires an open terminal. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open. Otherwise, just open your terminal like you normally would.

So, how you start with this ‘echo’ command:

You can also add quotes, and in some cases probably should:

You can also use the > operand and echo the text to a file. Like so:

Read: How To: Write Text To A File From The Terminal with “>” and “>>”

However, that’s not all you can do with the ‘echo’ command. You can also automatically fill in the information by way of environment variables. For example, try this:

Or you can try:

Read: How To: Show All Environment Variables

See? It’s good that I’ve written so many articles. I get to refer to ’em and save us all a bunch of time. So, be sure to visit those articles – especially if you’re a new user. If you’ve forgotten something, you can ‘echo’ the variable to be reminded.

Bonus:

This next bit is really just some information you’re gonna need down the road. I can sense it! This is a bit advanced for some of you, and you won’t need this until later in your Linux journey, but others will see this and suddenly understand the potential. If you’re new, you’ll get there.

The first thing we’re going to do is set a variable. It’s actually very easy to set your own variables in Linux. In this case, we’ll use:

Now, let’s just ‘echo’ the variable you just created:

Or, even better, you can then try:

See? It will output the variable when you echo it. You can create all the variables you’ll realistically ever need. 

You can actually format the output from the ‘echo’ command. For example, the -e flag with the \n separator. An example command looks like:

You can format the text in a variety of ways, just read the man page. You can do quite a lot with the ‘echo’ command and you should definitely check the man page if you’re interested in exploring all the possibilities:

There’s a ton of ways to use ‘echo’ (and with it variables) for those with a clever mind. When you do move on to learn about scripting, you’ll learn that it’s a basic tool used for all sorts of things, in all sorts of clever ways.

Closure:

And there you have it. You have a new article. This time, we’ve covered just the slightest bit of the ‘echo’ command. It’s enough to get your mind working, or so I hope. It’s enough to get a slight taste of the potential and to understand why you may want to be familiar with it.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Install ShellCheck So That You Can Use It Locally

If you’ve been writing shell scripts, or if you’re new to writing scripts, you may not know of ShellCheck – and you that can install ShellCheck for use locally. This means you don’t need to go online to check  your shell scripts, saving you time and effort – as well as being available offline.

If you don’t already know of ShellCheck, march your ass over there right this minute! It’s one of the greatest tools on the internet. If you’ve already read the whole linked page, you can pretty much skip this entire article! After all, it tells you how to install ShellCheck over there – and I’ll be duplicating a lot of that here.

Why am I duplicating it? Because so few people seem aware of it. So few people know this tool exists, even for online use. Time and time again, I see scripting questions that can be debugged/resolved using this wonderful ShellCheck tool.

So, like many of the articles on this site, it’s here so that we can link to this article and not have to repeat ourselves time and time again. Like much of the site, it’s meant to save time and to avoid duplicating effort!

There are other ways to use ShellCheck, such as directly in your editor. This article will not be covering those other ways, I’m simply going to tell you how to install it and use it from your terminal.

Install ShellCheck For Local Use:

Like so many of these things, you need to start with an open terminal. To do so, use your keyboard – just press CTRL + ALT + T and your default terminal should open. If it doesn’t, just open it from your application menu.

Once you have the terminal open, you can install ShellCheck. It’s available in most default repositories, so you shouldn’t have any issues installing it.

Debian/Ubuntu:

Arch/Manjaro:

Fedora:

OpenSUSE:

One of those ought to work. If not, follow the link in the second paragraph, poke around, and you’ll see that you can likely get ShellCheck installed with little or no difficulty. Worst case, you can grab the binaries and install it manually.

Using ShellCheck is even easier. You just use ‘shellcheck’ and then the path to the script. So, it’d look something like one of the following:

It’s really that easy. ShellCheck isn’t perfect and it doesn’t recognize every error, but it’ll catch a ton of beginner mistakes and typos. It’ll catch syntax issues and punctuation mistakes. It’s pretty handy and is absolutely a great tool for anyone that does any scripting at all.

Closure:

And there’s another article! This one will help you install ShellCheck, a fantastic tool for people who need to check their scripts. It’s right there in the application’s title! Really, more people need to be aware that it exists, and hopefully this article does a little something to help raise awareness.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.