12. 执行标志(e标志)


sed 替换标志e代表执行。 使用e标志,您可以将模式空间中可用的任何内容作为 shell 命令执行,并且输出将返回到模式空间。

注意:这仅在 GNU Sed 中可用。

创建以下文件,其中包含文件名列表及其完整路径。

$ cat files.txt
/etc/passwd
/etc/group

$ sed 's/^/ls -l /' files.txt
ls -l /etc/passwd
ls -l /etc/group
$ sed 's/^/ls -l /e' files.txt
-rw-r--r-- 1 root root 1547 Oct 27 08:11 /etc/passwd
-rw-r--r-- 1 root root 651 Oct 27 08:11 /etc/group