在bash中定义函数的区别

Str*_*sky 3 bash function

我已经看到函数在bashrc中定义了两种方式:

dosomething() { ... } 
Run Code Online (Sandbox Code Playgroud)

function dosomething() { ... } 
Run Code Online (Sandbox Code Playgroud)

使用function声明有什么不同?

plu*_*dra 5

http://www.gnu.org/s/bash/manual/bash.html#Shell-Functions

使用以下语法声明函数:

 [ function ] name () compound-command [ redirections ]
Run Code Online (Sandbox Code Playgroud)

这定义了一个名为name的shell函数.保留字功能是可选的.如果提供了功能保留字,则括号是可选的.

function省略括号是特定于bash的.所以为了更便携,不要使用它.