函数名在 bash 中有效但在 sh 中无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20771743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:05:46  来源:igfitidea点击:

Function name valid in bash but not in sh

bashshellsh

提问by user2064000

While playing around with bash and sh, I found out that the following is valid in bash:

在玩 bash 和 sh 时,我发现以下内容在 bash 中有效:

system.out.println () { printf ""; }

but not in sh:

但不是在 sh:

sh: `system.out.println': not a valid identifier

Why would this difference be there? Does the function defined above violate some convention (POSIX etc.) that causes this error?

为什么会有这种差异?上面定义的函数是否违反了导致此错误的某些约定(POSIX 等)?

回答by Noctua

It's just the dots, you can't use dots in shell function names. Or any variable name, for that matter.

这只是点,您不能在 shell 函数名称中使用点。或者任何变量名,就此而言。

I'll link you to this question: Allowed characters in linux environment variable names

我会将您链接到这个问题:Linux 环境变量名称中的允许字符