linux中echo命令_人们为什么在Linux中安装软件时使用“ echo”命令?
linux中echo命令
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.
如果您不熟悉Linux,那么许多命令及其变体可能会有些混乱。 以“ echo”命令为例。 人们为什么在安装软件时会使用它? 今天的SuperUser Q&A帖子回答了Linux新用户的问题。
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提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。
问题 (The Question)
SuperUser reader PallavBakshi wants to know why people use the “echo” command when installing software in Linux:
超级用户阅读器PallavBakshi想知道为什么人们在Linux中安装软件时使用“ echo”命令:
I am new to the computing world. While installing ROS Indigo, the first step said that I should use the following code:
我是计算机世界的新手。 在安装ROS Indigo时,第一步是说我应该使用以下代码:
- sudo sh -c ‘echo “deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main” > /etc/apt/sources.list.d/ros-latest.list’ sudo sh -c'回显“ 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.
人们为什么在这种情况下将“ echo”命令与“ sh -c”一起使用? 我也看到了在其他安装过程中使用的“ echo”命令。
Links I Looked Through
我浏览过的链接
Why do people use the “echo” command when installing software in Linux?
人们为什么在Linux中安装软件时使用“ echo”命令?
答案 (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.
通常,“ echo”命令的功能是在控制台上显示一个字符串(文本)。 但是这一次,在echo命令之后添加了(大于)>字符,将其输出重定向到/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.
对于每台计算机,写入文件的字符串可能会有所不同。 $(lsb_release -sc)部分在运行“ echo”命令时已解析(更改为其他内容)。
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.
您可以在命令之前和之后在文本编辑器中打开/etc/apt/sources.list.d/ros-latest.list来自己查看更改。 请记住,使用此命令之前该文件可能不存在。
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.
有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程。
linux中echo命令