Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are double colons :: in a shell script?

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

like image 701
reachlin Avatar asked Jun 15 '17 03:06

reachlin


People also ask

What does a leading colon (:) mean in a script?

© 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 :").

What is double semicolon in shell script?

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.

What is $$ in shell script?

$$ The process number of the current shell. For shell scripts, this is the process ID under which they are executing. 8.

What does || mean in scripting?

The || is an “or” comparison operator. The : is a null operator which does… Nothing.


3 Answers

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.

like image 126
A Monad is a Monoid Avatar answered Oct 11 '22 19:10

A Monad is a Monoid


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.

like image 37
daidoji70 Avatar answered Oct 11 '22 21:10

daidoji70


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.

like image 24
Mateusz Piotrowski Avatar answered Oct 11 '22 21:10

Mateusz Piotrowski