【发布时间】:2016-08-17 03:53:43
【问题描述】:
以下代码:
#!/bin/bash
function me-test()
{
echo 'test'
}
me-test
下面的执行方法不正确:
#sh 1.sh
1.sh: line 6: `me-test': not a valid identifier
但是下面的执行方法是正确的:
#./1.sh
test
在其他编程语言中,不能使用破折号来定义函数,例如python。
为什么shell会这样?
【问题讨论】:
-
另外,
function语法不是标准的,可能不适用于所有 posix 兼容的 shell。