Wednesday, 30 October 2019

How to Use the Echo Command on Linux

A Linux terminal window on a Ubuntu-themed desktop.
Fatmawati Achmad Zaenuri/Shutterstock

The echo command is perfect for writing formatted text to the terminal window. And it doesn’t have to be static text. It can include shell variables, filenames, and directories. You can also redirect echo to create text files and log files. Follow this simple guide to find out how.

Echo Repeats What You Tell It To Repeat

Zeus was fond of leaving Mount Olympus to consort with beautiful nymphs. On one trip, he told a mountain nymph called Echo to waylay his wife, Hera, if she followed him. Hera did come looking for Zeus, and Echo did all she could to keep Hera in conversation. Finally, Hera lost her temper and cursed poor Echo so that she only repeat the last words that someone else had said. What Hera did to Zeus when she caught up with him is anybody’s guess.

And that, pretty much, is echo‘s lot in life. It repeats what it has been told to repeat. That’s a simple function, but a vital one. Without echo , we’d be unable to get visible output from shell scripts, for example.

Whilst not laden down with a multitude of bells and whistles, there’s a good chance that echo has some capabilities that you didn’t know about or that you’d forgotten.

echo? echo!

Most Linux systems provide two versions of echo. The Bash shell has its own echo built into it, and there’s a binary executable version of echo as well.

We can see the two different versions by using the following commands:

type echo
whereis echo

type echo in a terminal window

The type command tells us whether the command we pass to it as its argument is a shell builtin, a binary executable, an alias, or a function. It reports to us that echo is a shell builtin.

As soon as it has found an answer, type stops looking for further matches. So it doesn’t tell us if there are other commands with the same name present in the system. But it does tell us which one it finds first. And that’s the one that will be used by default when we issue that command.

Read the remaining 68 paragraphs



from How-To Geek https://ift.tt/31SeLsB

No comments:

Post a Comment