【发布时间】:2017-03-05 12:52:33
【问题描述】:
我这里有一个脚本文件,叫做editfile.script:
#!/bin/bash
sed '{
1i \Game Commence\nAre You Ready???\
s/game/Game/g
s/points/Points/g
s/the\sthe/the/g
/^ *$/d
$a It's time
}' "$1"
编辑这个名为GameOverview的文件
This game will begin in 3 minutes.
The objective is to score 10 points.
If you score 10 points, u move to the the next round
Good luck, may the the force b w u
现在,当我运行 .\editfile.script GameOverview(从 C shell)命令行时,我会收到以下输出:
Game Commence
Are You Ready???
This Game will begin in 3 minutes.
The objective is to score 10 Points.
If you score 10 points, u move to the next round
Good luck, may the force b w u
如您所见,每个命令都已执行:除了追加命令$a It's time。为什么会发生这种情况,以及如何解决?而且我相信它与前面的“删除所有空白行”命令/^ *$/d有关,因为当我摆脱它时,附加了“是时候”了:
Game Commence
Are You Ready???
This Game will begin in 3 minutes.
The objective is to score 10 Points.
If you score 10 points, u move to the next round
Good luck, may the force b w u
It's time
【问题讨论】: