英文:
Commands in awk
问题
在awk
文件中,需要在每个命令的末尾加上分号(;
)吗?
title = gensub (beg_ere, "\", 1, $0);
subtitle = gensub (beg_ere, "\", 1, $0);
keywords = gensub (beg_ere, "\", 1, $0);
nu = split (ukeys, uaggr, ",");
nk = split (keywords, kaggr, ",");
英文:
Do I need to have ;
at the end of each command in awk
files.
title = gensub (beg_ere, "\", 1, $0);
subtitle = gensub (beg_ere, "\", 1, $0);
keywords = gensub (beg_ere, "\", 1, $0);
nu = split (ukeys, uaggr, ",");
nk = split (keywords, kaggr, ",");
答案1
得分: 0
以下是已翻译的内容:
awk语法 包含以下定义:
program : item_list
| item_list item
;
item_list : /* empty */
| item_list item terminator
;
和
terminator : terminator NEWLINE
| ';'
| NEWLINE
;
因此,不,你并不总是需要分号。只有当你试图将两个项放在同一行时才需要分号(即没有换行符之间)。
英文:
The awk grammar contains the definitions:
program : item_list
| item_list item
;
item_list : /* empty */
| item_list item terminator
;
and
terminator : terminator NEWLINE
| ';'
| NEWLINE
;
So, no, you do not always need a semi-colon. Only if you are trying to put two items on the same line (ie. no newline in between).
答案2
得分: 0
在AWK文件中,每个命令的结尾是否需要分号?《AWK编程语言》关于操作(Actions)的部分提到:
有时,一个操作非常简单:只是一个单独的打印(print)或赋值(assignment)操作。其他时候,它可能是一系列由换行符或分号分隔的多个语句的序列。(...)
这意味着只使用换行或只使用分号来分隔操作是足够的。
英文:
> Do I need to have ; at the end of each command in awk files.
The AWK programming language says about Actions that
> Sometimes an action is very simple: a single print or assignment.
> Other times, it may be a sequence of several statements separated by
> newlines or semicolons.(...)
which means using only newline or only semicolon to separate is enough.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论