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.
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 http://packages.ros.org/ros/ubuntu $(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?
Why do people use the “echo” command when installing software in Linux?
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. 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.
- › Which Browser Offers the Best Privacy Protection?
- › The Meta Quest 2 Is Returning to Its Original Price
- › Clean Without Compromise and Save on the Roborock S7 Max Ultra
- › Dark Mode Is Coming to Windows Paint
- › Jam Outdoors With This Harman Portable Speaker, Now $199.99
- › The Meta Quest 3 Will Have a 2x GPU Boost and a Price Hike