Follow us on Twitter

Why Do People Use the “echo” Command When Installing Software in Linux?


If you are new to using Linux, then many of the commands and variations thereof may seem a bit confusing. Take the “echo” command, for example. Why do people use it when installing software? Today’s SuperUser Q&A post has the answer to a new Linux user’s question.

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

The Question

SuperUser reader PallavBakshi wants to know why people use the “echo” command when installing software in Linux:

I am new to the computing world. While installing ROS Indigo, the first step said that I should use the following code:

  • sudo sh -c ‘echo “deb $(lsb_release -sc) main” > /etc/apt/sources.list.d/ros-latest.list’

Why do people use the “echo” command along with “sh -c” in this context? I have seen the “echo” command used in other installation processes as well.

Links I Looked Through

What Exactly is the “sh” Command?

Ubuntu Install of ROS Indigo

Why do people use the “echo” command when installing software in Linux?

The Answer

SuperUser contributor Fleet Command has the answer for us:

Ordinarily, the function of the “echo” command is to display a string (piece of text) on the console. But this time, a (greater than) > character is added after the echo command, redirecting its output to a text file located in /etc/apt/sources.list.d/ros-latest.list.

Basically, this whole command writes a piece of text to a text file (overwrites the text file and appends information to the end). Now, here comes the tricky part:

The string written to the file may be different for each computer. The part, $(lsb_release -sc), is resolved (changed into something else) when the “echo” command runs.

You can open /etc/apt/sources.list.d/ros-latest.list in a text editor before and after the command to see the changes for yourself. Keep in mind that the file might not exist before using this command.

Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

Akemi Iwaya is a devoted Mozilla Firefox user who enjoys working with multiple browsers and occasionally dabbling with Linux. She also loves reading fantasy and sci-fi stories as well as playing “old school” role-playing games. You can visit her on Twitter and .

How to Take a Screenshot on Your iPhone or iPad
How to Upload Your Music Library to Google Play Music