gpt4 book ai didi

sed - 在 sed 中使用分号作为命令分隔符有多便携?

转载 作者:行者123 更新时间:2023-12-04 01:03:04 25 4
gpt4 key购买 nike

在 sed 中,使用分号分隔的多个命令是相当常见的:

$ sed -e '/re/{s//replace/p; q;}

但是,标准(例如 http://pubs.opengroup.org/onlinepubs/9699919799/ )只允许
换行符作为分隔符:

$ sed -e '/re/{
s//替换/p
q
}

是否有许多常见的 sed 实现仍在使用中不允许使用分号? IOW,打算可移植的 sed 脚本可以使用分号吗?

最佳答案

来自 the POSIX specification of sed :

Command verbs other than {, a, b, c, i, r, t, w, :, and # can be followed by a <semicolon>, optional <blank> characters, and another command verb. However, when the s command verb is used with the w flag, following it with another command in this manner produces undefined results.



所以除了上面提到的那些命令之外,大多数命令都可以用分号分隔。
/[^\{abcirtw:#];[[:space:]]*/ :-)

关于sed - 在 sed 中使用分号作为命令分隔符有多便携?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6280599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com