Bash script function names containing double colon '::'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
15
down vote

favorite
3












I came across a Bash script today that has function names with double colons :: in them, e.g., file::write() and file::read(). I've never seen this syntax before in a Bash script, and when I invoked the script it ran just fine (to my surprise).



After scouring Bash's man page on my system (and online) I cannot find anything in the documentation that supports this syntax for function names. For example, the section Shell Defined Functions defines the syntax for a shell function to be



function name [()] compound-command [redirection]


and then (elsewhere in the manual) the token name is defined as



name A word consisting only of alphanumeric characters and
underscores, and beginning with an alphabetic character
or an underscore. Also referred to as an identifier.


There's no mention anywhere of the double colon syntax for function names.



The only other reference to this double colon syntax that I've found thus far is in this Shell Style Guide (see the subsection Naming Conventions > Function Names) which recommends using the double colon syntax for function names in "packages"--e.g., mypackage::myfunction().



Is this double colon syntax for function names a legitimate feature of the Bash shell, or is it perhaps an undocumented feature? If it's legit, where is it documented in the Bash manual? I've looked and looked but I can't find anything about it in the manual. The closest I've found is the use of :: in the PATH environment variable to add the current working directory to the search path.



EXAMPLE



#!/bin/bash
function abc::def()
echo "$FUNCNAME[0]"

abc::def


I tested this script on three different Linux distros, and on all three the script prints abc::def to stdout.







share|improve this question




















  • They're allowed - stackoverflow.com/questions/44558080/…
    – slm♦
    Aug 20 at 6:41










  • One may also see %% in function names unix.stackexchange.com/questions/401166/…
    – michael
    Aug 20 at 12:55










  • Thanks for the links. Odd. Prior to posting I searched for "bash double colon" (w/o the quotes) but didn't find anything. Apologies for re-asking an already answered question. .
    – Jim Fischer
    Aug 20 at 18:02














up vote
15
down vote

favorite
3












I came across a Bash script today that has function names with double colons :: in them, e.g., file::write() and file::read(). I've never seen this syntax before in a Bash script, and when I invoked the script it ran just fine (to my surprise).



After scouring Bash's man page on my system (and online) I cannot find anything in the documentation that supports this syntax for function names. For example, the section Shell Defined Functions defines the syntax for a shell function to be



function name [()] compound-command [redirection]


and then (elsewhere in the manual) the token name is defined as



name A word consisting only of alphanumeric characters and
underscores, and beginning with an alphabetic character
or an underscore. Also referred to as an identifier.


There's no mention anywhere of the double colon syntax for function names.



The only other reference to this double colon syntax that I've found thus far is in this Shell Style Guide (see the subsection Naming Conventions > Function Names) which recommends using the double colon syntax for function names in "packages"--e.g., mypackage::myfunction().



Is this double colon syntax for function names a legitimate feature of the Bash shell, or is it perhaps an undocumented feature? If it's legit, where is it documented in the Bash manual? I've looked and looked but I can't find anything about it in the manual. The closest I've found is the use of :: in the PATH environment variable to add the current working directory to the search path.



EXAMPLE



#!/bin/bash
function abc::def()
echo "$FUNCNAME[0]"

abc::def


I tested this script on three different Linux distros, and on all three the script prints abc::def to stdout.







share|improve this question




















  • They're allowed - stackoverflow.com/questions/44558080/…
    – slm♦
    Aug 20 at 6:41










  • One may also see %% in function names unix.stackexchange.com/questions/401166/…
    – michael
    Aug 20 at 12:55










  • Thanks for the links. Odd. Prior to posting I searched for "bash double colon" (w/o the quotes) but didn't find anything. Apologies for re-asking an already answered question. .
    – Jim Fischer
    Aug 20 at 18:02












up vote
15
down vote

favorite
3









up vote
15
down vote

favorite
3






3





I came across a Bash script today that has function names with double colons :: in them, e.g., file::write() and file::read(). I've never seen this syntax before in a Bash script, and when I invoked the script it ran just fine (to my surprise).



After scouring Bash's man page on my system (and online) I cannot find anything in the documentation that supports this syntax for function names. For example, the section Shell Defined Functions defines the syntax for a shell function to be



function name [()] compound-command [redirection]


and then (elsewhere in the manual) the token name is defined as



name A word consisting only of alphanumeric characters and
underscores, and beginning with an alphabetic character
or an underscore. Also referred to as an identifier.


There's no mention anywhere of the double colon syntax for function names.



The only other reference to this double colon syntax that I've found thus far is in this Shell Style Guide (see the subsection Naming Conventions > Function Names) which recommends using the double colon syntax for function names in "packages"--e.g., mypackage::myfunction().



Is this double colon syntax for function names a legitimate feature of the Bash shell, or is it perhaps an undocumented feature? If it's legit, where is it documented in the Bash manual? I've looked and looked but I can't find anything about it in the manual. The closest I've found is the use of :: in the PATH environment variable to add the current working directory to the search path.



EXAMPLE



#!/bin/bash
function abc::def()
echo "$FUNCNAME[0]"

abc::def


I tested this script on three different Linux distros, and on all three the script prints abc::def to stdout.







share|improve this question












I came across a Bash script today that has function names with double colons :: in them, e.g., file::write() and file::read(). I've never seen this syntax before in a Bash script, and when I invoked the script it ran just fine (to my surprise).



After scouring Bash's man page on my system (and online) I cannot find anything in the documentation that supports this syntax for function names. For example, the section Shell Defined Functions defines the syntax for a shell function to be



function name [()] compound-command [redirection]


and then (elsewhere in the manual) the token name is defined as



name A word consisting only of alphanumeric characters and
underscores, and beginning with an alphabetic character
or an underscore. Also referred to as an identifier.


There's no mention anywhere of the double colon syntax for function names.



The only other reference to this double colon syntax that I've found thus far is in this Shell Style Guide (see the subsection Naming Conventions > Function Names) which recommends using the double colon syntax for function names in "packages"--e.g., mypackage::myfunction().



Is this double colon syntax for function names a legitimate feature of the Bash shell, or is it perhaps an undocumented feature? If it's legit, where is it documented in the Bash manual? I've looked and looked but I can't find anything about it in the manual. The closest I've found is the use of :: in the PATH environment variable to add the current working directory to the search path.



EXAMPLE



#!/bin/bash
function abc::def()
echo "$FUNCNAME[0]"

abc::def


I tested this script on three different Linux distros, and on all three the script prints abc::def to stdout.









share|improve this question











share|improve this question




share|improve this question










asked Aug 20 at 4:10









Jim Fischer

30819




30819











  • They're allowed - stackoverflow.com/questions/44558080/…
    – slm♦
    Aug 20 at 6:41










  • One may also see %% in function names unix.stackexchange.com/questions/401166/…
    – michael
    Aug 20 at 12:55










  • Thanks for the links. Odd. Prior to posting I searched for "bash double colon" (w/o the quotes) but didn't find anything. Apologies for re-asking an already answered question. .
    – Jim Fischer
    Aug 20 at 18:02
















  • They're allowed - stackoverflow.com/questions/44558080/…
    – slm♦
    Aug 20 at 6:41










  • One may also see %% in function names unix.stackexchange.com/questions/401166/…
    – michael
    Aug 20 at 12:55










  • Thanks for the links. Odd. Prior to posting I searched for "bash double colon" (w/o the quotes) but didn't find anything. Apologies for re-asking an already answered question. .
    – Jim Fischer
    Aug 20 at 18:02















They're allowed - stackoverflow.com/questions/44558080/…
– slm♦
Aug 20 at 6:41




They're allowed - stackoverflow.com/questions/44558080/…
– slm♦
Aug 20 at 6:41












One may also see %% in function names unix.stackexchange.com/questions/401166/…
– michael
Aug 20 at 12:55




One may also see %% in function names unix.stackexchange.com/questions/401166/…
– michael
Aug 20 at 12:55












Thanks for the links. Odd. Prior to posting I searched for "bash double colon" (w/o the quotes) but didn't find anything. Apologies for re-asking an already answered question. .
– Jim Fischer
Aug 20 at 18:02




Thanks for the links. Odd. Prior to posting I searched for "bash double colon" (w/o the quotes) but didn't find anything. Apologies for re-asking an already answered question. .
– Jim Fischer
Aug 20 at 18:02










1 Answer
1






active

oldest

votes

















up vote
15
down vote



accepted










This is a case of the documentation being stricter than the implementation, possibly in an attempt to lower the footgun factor. This has been discussed here before; see also the exhaustive test establishing that for example [} is a valid function name.



It may also be worth noting that abc::def is not a valid variable name:



$ abc::def=foo
bash: abc::def=foo: command not found





share 






Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463560%2fbash-script-function-names-containing-double-colon%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
15
down vote



accepted










This is a case of the documentation being stricter than the implementation, possibly in an attempt to lower the footgun factor. This has been discussed here before; see also the exhaustive test establishing that for example [ is a valid function name.



It may also be worth noting that abc::def is not a valid variable name:



$ abc::def=foo
bash: abc::def=foo: command not found





share is valid posix
– Steven Penny
Aug 20 at 13:27










share 








up vote
15
down vote



accepted







up vote
15
down vote



accepted






This is a case of the documentation being stricter than the implementation, possibly in an attempt to lower the footgun factor. This has been discussed here before; see also the exhaustive test establishing that for example [ is a valid function name.



It may also be worth noting that abc::def is not a valid variable name:



$ abc::def=foo
bash: abc::def=foo: command not found





shareimprove this answer



share is valid posix
– Steven Penny
Aug 20 at 13:27














3




3




just to make it vividly clear - not file::read nor [ is valid posix
– Steven Penny
Aug 20 at 13:27




just to make it vividly clear - not file::read nor [{ is valid posix
– Steven Penny
Aug 20 at 13:27

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463560%2fbash-script-function-names-containing-double-colon%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

One-line joke