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

标签 bash shell sh

<分区>

在使用 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/

相关文章:

linux - 有没有办法告诉 sed 忽略符号链接(symbolic link)?

arrays - 为什么我的数组对于我的 shell 脚本不正确?

path - 在 $PATH 上查找命令

bash - 如何处理 shell 脚本参数中的 "--"?

bash - 将 linux "cut"与标准输入一起使用

bash - Bash 中的模式匹配

file - 根据名称在终端中移动内容

linux - 我删除目录后登录bash总是提示 "shell-init error retrieving current directory getcwd solve"

使用 dup2 创建管道

linux - 如果有尾随字段,为什么 sort 命令排序不同?