里面的外壳# (( ))
我是外壳新手。我不太明白以下功能。这个函数基本上将小时增加 1。
我想知道为什么开发人员在 $g_current_hour+1 前面放“10#”。据我了解,shell中的dose#表示注释?
f_increment_hour() {
g_next_hour=$((10#$g_current_hour+1))
}
I am new to shell. I am not quite understand the following function. This function basically increase the hour by 1.
I am wondering why the developer put "10#" in front of $g_current_hour+1. From my understanding, dose # in shell means comments?
f_increment_hour() {
g_next_hour=$((10#$g_current_hour+1))
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一切都取决于上下文。这里
10#
表示以 10 为基数。Everything depends on the context. Here
10#
means base 10.'#' 将被解释为标记的一部分,除非它前面有空格、换行符或分号。
(或任何其他非单词符号)
语言规范的第 2.3 节“令牌识别”指出:
当 shell 解析其输入并读取“foo#bar”时,因为它正在处理“#”字符,所以它应用规则 9并将 # 附加到标记中。一旦应用了规则 9,它就会停止检查并且永远不会考虑规则 10。如果“#”之前的字符是空格,则规则 9 不适用,因此检查规则 10 并开始注释。
换句话说,只有当“#”前面的字符不是单词的一部分(例如空格或分号)时,“#”才会开始注释,因此“foo#bar”是一个标记,而不是“foo”后跟一个注释,但“foo #bar”是标记“foo”后跟注释。
'#' will be interpreted as part of a token unless it is preceded by a space, newline, or semi-colon.
(or any other non-word symbol)
Section 2.3 "Token recognition" of the language spec, states:
When the shell is parsing its input and reads "foo#bar", as it is processing the '#' character it applies rule 9 and appends the # to the token. Once rule 9 is applied, it stops checking and rule 10 is never considered. If the character preceding the '#' is whitespace, then rule 9 does not apply, so rule 10 is checked and a comment is started.
In other words, a '#' only starts a comment if the character preceded it is not part of a word ( eg whitespace or semi-colon), so "foo#bar" is one token, and not "foo" followed by a comment, but "foo #bar" is the token "foo" followed by a comment.