bash 什么是 shell 脚本中的双冒号 ::?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44558080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are double colons :: in a shell script?
提问by reachlin
What is double colon ::
in shell scripts? like this piece of script:
::
shell 脚本中的双冒号是什么?像这段脚本:
function guess_built_binary_path {
local hyperkube_path=$(kube::util::find-binary "hyperkube")
if [[ -z "${hyperkube_path}" ]]; then
return
fi
echo -n "$(dirname "${hyperkube_path}")"
}
I found it in here:
我在这里找到它:
https://github.com/kubernetes/kubernetes/blob/master/hack/local-up-cluster.sh
https://github.com/kubernetes/kubernetes/blob/master/hack/local-up-cluster.sh
采纳答案by Damián Rafael Lattenero
The ::
is just a Naming Conventionfor function names. Is a coding-style such as snake_caseor CamelCase
该::
只是一个命名约定的函数名。是snake_case或CamelCase等编码风格
The convention for Function namesin shell style commonly is:
shell 样式中函数名称的约定通常是:
Lower-case, with underscores to separate words. Separate libraries with ::. Parentheses are required after the function name. The keyword function is optional, but must be used consistently throughout a project.
小写,用下划线分隔单词。用 :: 分隔库。函数名后需要括号。关键字 function 是可选的,但必须在整个项目中一致使用。
You can check here.
你可以在这里查看。
回答by Mateusz Piotrowski
Although it seems like Bash allows putting colons in function names, this behaviour is not standardized by POSIX.
尽管 Bash 似乎允许在函数名称中放置冒号,但 POSIX 并未对这种行为进行标准化。
Function names should consist of underscores, digits, and letters from the portable set.
函数名应该由可移植集合中的下划线、数字和字母组成。
回答by daidoji70
It's nothing, these colons are part of the command names apparently. You can verify yourself by creating and running a command with :
in the name. The shell by default will autoescape them and its all perfectly legal.
没什么,这些冒号显然是命令名称的一部分。您可以通过:
在名称中创建和运行命令来验证自己。默认情况下,shell 会自动转义它们,这一切都是完全合法的。