linux - 有谁知道这是什么意思? -----> sed : -e expression #1, 字符 28:未知命令: `.'

标签 linux

\#Add another new line of text to hosts and send the output to       

hosts_update.sh
sed '/localhost/a\

# Gateway
10.0.0.1    it20.it.cs.umb.edu  it20

# Addresses for the Windows PCs
10.0.0.240  it21.it.cs.umb.edu it21\
10.0.0.241  it22.it.cs.umb.edu it22\
10.0.0.242  it23.it.cs.umb.edu it23\
10.0.0.243  it24.it.cs.umb.edu it24\
10.0.0.244  it25.it.cs.umb.edu it25\
10.0.0.245  it26.it.cs.umb.edu it26\
10.0.0.246  it27.it.cs.umb.edu it27\
10.0.0.247  it28.it.cs.umb.edu it28\
' hosts > hosts_update.sh

最佳答案

首先,您最初的几行代码看起来与 shell 脚本不符。看起来你的 hosts_update.sh 行应该是评论的一部分(而且评论不应该以 \ 开头):

# Add another new line of text to hosts and send the output
#   to hosts_update.sh

其次,您需要在行的末尾添加一个\,您要附加sed,目前您只有它在某些选择行上。考虑到这一点,这个脚本可能就是您想要的:

# Add another new line of text to hosts and send the output
#   to hosts_update.sh

sed '/localhost/a\
\
# Gateway\
10.0.0.1    it20.it.cs.umb.edu  it20\
\
# Addresses for the Windows PCs\
10.0.0.240  it21.it.cs.umb.edu it21\
10.0.0.241  it22.it.cs.umb.edu it22\
10.0.0.242  it23.it.cs.umb.edu it23\
10.0.0.243  it24.it.cs.umb.edu it24\
10.0.0.244  it25.it.cs.umb.edu it25\
10.0.0.245  it26.it.cs.umb.edu it26\
10.0.0.246  it27.it.cs.umb.edu it27\
10.0.0.247  it28.it.cs.umb.edu it28\
' hosts > hosts_update.sh

你的情况实际发生了什么(没有 \ 连续字符):

sed '/localhost/a\

# Gateway
10.0.0.1    it20.it.cs.umb.edu  it20

是这样的:

  • localhost 之后追加一个空行;
  • 然后你有一个sed注释行;
  • 然后您告诉 sed 在第 10 行执行 .

在那一点上,sed 正确地提示它不知道如何处理 . 命令:-)

我会说,根据经验,脚本的早期(工作)迭代只有 it21-28 行,有人(错误地)添加了 it20和评论/空白行。这是基于只有那些行是错误的这一事实。然而,这只是(有根据的)推测,不会影响答案。

最后,您可能不想调用结果文件 hosts_update.sh,人们几乎肯定会认为它是一个 shell 脚本而不是主机文件它实际上是。

关于linux - 有谁知道这是什么意思? -----> sed : -e expression #1, 字符 28:未知命令: `.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47625596/

相关文章:

c++ - 即使 stdout 和 stderr 被重定向,Unix 程序如何在屏幕上显示输出?

c# - 如何使用单声道将 .NET Windows 服务应用程序迁移到 Linux?

linux - 查找所有文件并将特定文件解压缩到本地文件夹

r - 谁能帮我解决这个 crontab?

linux - 使用 Linux 命令清理 CSV 文件,同时忽略引号之间的逗号

linux - 两个不同版本的安装库

PHP ini 文件设置 Linux

linux - 服务器发送复位信号而不是FIN

c++ - 如何在 C++ 中读取一堆字符串?

linux - "Couldn' t 在 Windows 上的 Ubuntu bash 上找到引用控制台的文件描述符