Bash script function names containing double colon '::'
Clash Royale CLAN TAG#URR8PPP
up vote
15
down vote
favorite
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.
bash syntax bash-functions
add a comment |Â
up vote
15
down vote
favorite
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.
bash syntax bash-functions
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
add a comment |Â
up vote
15
down vote
favorite
up vote
15
down vote
favorite
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.
bash syntax bash-functions
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.
bash syntax bash-functions
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
add a comment |Â
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
add a comment |Â
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
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
add a comment 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
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
add a comment 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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