【问题标题】:I keep getting unexpected token `/bin/busybox.exe' error in sed. How can I resolve this?我在 sed 中不断收到意外的令牌“/bin/busybox.exe”错误。我该如何解决这个问题?
【发布时间】:2019-10-06 08:38:26
【问题描述】:

我可以修改单个文件的头和尾,如下所示:

header1=randomstring,header2=0000
body body body
header1=randomerstring,header2=00000

使用这个命令:

sed "s/header1=.*header2=/header1=teststring1.teststring2.$(date +%d%m%Y)teststring3,header2=/" file

得到:

header1=teststring1.teststring2051919teststring3,header2=0000
body body body
header1=teststring1.teststring2051919teststring3,header2=00000

当我尝试使用 for 循环(见下文)将上述命令应用于具有相同前缀的多个文件时,我不断收到此错误:bash: syntax error near unexpected token `/bin/busybox.exe'。我怎样才能解决这个问题?还有单个文件的命令,打印出文件内容,我想在遍历文件时删除它,我只是不确定要删除什么。

下面是产生错误的for循环命令:

for file in fileprefix.*; sed "s/header1=.*header2=/header1=teststring1.teststring2.$(date +%d%m%Y)teststring3,header2=/" i; done

同样,错误是bash: syntax error near unexpected token `/bin/busybox.exe'.

【问题讨论】:

  • 您缺少do
  • 将您的代码复制/粘贴到shellcheck.net 并修复它报告的错误消息。

标签: linux bash sed syntax busybox


【解决方案1】:

在循环中的“sed”前面放一个do,它应该可以工作; do 和 done 只能成对出现。

【讨论】:

  • 哇,我看这个太久了 -_- 谢谢!
猜你喜欢
  • 2023-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-18
  • 1970-01-01
  • 1970-01-01
  • 2013-11-23
  • 2021-07-01
相关资源
最近更新 更多