Is it possible to use the "@" symbol as a function name in a bash script? The following does not work:
function @() {
echo hello
}
EDIT 2: While EDIT 1: To clarify, it is not allowed per the definition of an identifier. I'm not recommending it. I'm just saying that for backwards compatibility, it is possible in bash to use
Some people alias The main reason why I would not use BTW: Works the same in zsh. |
|||||||||||||||||||||
|
From
|
|||||
|
The naming of functions is quite similar to the allowed characters for alias:
So, except for: / $ ` = | & ; ( ) < > space tab any other character should be valid for alias and function names. However, the character So, this should fail:
However, this works:
And this should work as well:
It is also possible to do this:
An alias is flexible in what symbols it accepts. |
||||
|
4.3.42(1)-release
(Arch Linux, package4.3.042-4
), the function definition as given in the question doesn't give an error, but running@
gives@: command not found
. Ditto on4.3.11(1)-release
(Ubuntu 14.04, bash package4.3-7ubuntu1.5
).export -f @
givesexport: @: not a function
. – muru Feb 20 at 3:44extglob
. Never mind. – muru Feb 20 at 4:12