这在 shell 脚本中是什么意思?
| sed 's/ /':'/' | sed 's/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)
假设上下文是
some-command | sed 's/ /':'/' | sed 's/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)
让我们一块一块地拆开它。例如,假设some-command
是echo 'test of the command'
。
然后sed 's/ /':'/'
用 替换第一个空格:
。
test of the command
? test:of the command
之后,sed 's/ /-/'
将新的第一个空格替换为-
test:of the command
? test:of-the command
此转换应用于 的输出的每一行some-command
。
正如@Philippos 在评论中提到的,目前还不清楚为什么:
这里没有引用。这会更好
some-command | sed 's/ /:/' | sed 's/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)
但sed
不限于每个实例一次替换。所以更好的是
some-command | sed 's/ /:/; s/ /-/' > file.list
Run Code Online (Sandbox Code Playgroud)