<分区>
在使用 bash 和 sh 时,我发现以下内容在 bash 中有效:
system.out.println () { printf "$1"; }
但不在 sh 中:
sh: `system.out.println': not a valid identifier
为什么会有这种差异?上面定义的函数是否违反了导致此错误的某些约定(POSIX 等)?
<分区>
在使用 bash 和 sh 时,我发现以下内容在 bash 中有效:
system.out.println () { printf "$1"; }
但不在 sh 中:
sh: `system.out.println': not a valid identifier
为什么会有这种差异?上面定义的函数是否违反了导致此错误的某些约定(POSIX 等)?
最佳答案
只是点,你不能在 shell 函数名中使用点。或者任何变量名,就此而言。
我会将您链接到这个问题:Allowed characters in linux environment variable names
关于bash - 函数名在 bash 中有效但在 sh 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20771743/