What is double colon ::
in shell scripts? like this piece of script:
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
© March 2010 Anthony Lawrence. Bash and sh both use colons (":") in more than one context. You'll see it used as a separator ($PATH, for example), as a modifier (${n:="foo"}) and as a null operator ("while :").
The double semicolon is also useful as it leaves no ambiguity in the code. It is required as it is used at the end of each clause as required by the bash syntax in order to parse the command correctly. It is only used in case constructs to indicate that the end of an alternative.
$$ The process number of the current shell. For shell scripts, this is the process ID under which they are executing. 8.
The || is an “or” comparison operator. The : is a null operator which does… Nothing.
The ::
is just a Naming Convention for function names. Is a coding-style such as snake_case or CamelCase
The convention for Function names in shell style commonly is:
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.
You can check here.
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.
Although it seems like Bash allows putting colons in function names, this behaviour is not standardized by POSIX.
Function names should consist of underscores, digits, and letters from the portable set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With