【问题标题】:Is this shell script correct?这个shell脚本正确吗?
【发布时间】:2015-04-19 06:15:52
【问题描述】:

我有一个这样的shell script

 sed -i '/^###########/,/^#End of Build.Prop/d' /system/build.prop;
 #
 sed -i '/^#Start Build.Prop Tweak/,/^#End of Build.Prop Tweak/d' /system/build.prop;
 #
 sed -i '/^#Start Build.Prop Tweak/,/^ro\.config\.hwfeature_wakeupkey=0/d' /system/build.prop;

在上述三个 Shell 命令中,当放入 sh 文件时,它们都不起作用。但是,如果我使用 TerminalEmulator,这三个脚本都可以执行

我想在 Android 设备中使用脚本

【问题讨论】:

  • 这三个脚本在 sh 文件中不起作用,我通过 clkworkmod 刷新它
  • 使用-e选项可以将三个命令合二为一。

标签: android shell sed


【解决方案1】:

不行,太危险了。
当结束搜索标签丢失时,您将删除文件的大部分。 当您想删除文件中的第一行和第二行时,它似乎工作正常:

$ cat test.txt
first line
second line
third line

$ cat test.txt | sed '/first/,/second/ d'
third line

编辑:使用sed '/first/,/second/ d' test.txt 减少一个命令

但是当第二行找不到时会发生什么?
您的 sed 命令应该跳过删除行,但它会:

$ cat test.txt | sed '/first/,/mistake/ d'
$

编辑:使用sed '/first/,/mistake/ d' test.txt 减少一个命令

第一个匹配的所有行都被删除了!

【讨论】:

  • 我使用我的第二个脚本并且工作正常。它删除了一些我想要的行
  • @Ed Thx,一个坏习惯。
猜你喜欢
  • 2011-10-21
  • 2017-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-17
  • 1970-01-01
  • 2023-03-20
  • 2014-10-05
相关资源
最近更新 更多