shell 脚本中的双冒号 :: 是什么?

What are double colons :: in a shell 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}")"
}

我在这里找到它:

https://github.com/kubernetes/kubernetes/blob/master/hack/local-up-cluster.sh

没什么,这些冒号显然是命令名称的一部分。您可以通过创建和 运行 名称中包含 : 的命令来验证自己。默认情况下 shell 会自动转义它们,并且完全合法。

:: 只是 命名约定 用于 函数名称 。是一种编码风格,例如 snake_case or CamelCase

函数名称在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.

您可以检查here

虽然 Bash 似乎允许在函数名称中使用冒号,但 this behaviour is not standardized by POSIX

函数名称应由 the portable set.

中的下划线、数字和字母组成