我已经看到函数在bashrc中定义了两种方式:
dosomething() { ... }
Run Code Online (Sandbox Code Playgroud)
和
function dosomething() { ... }
Run Code Online (Sandbox Code Playgroud)
使用function声明有什么不同?
http://www.gnu.org/s/bash/manual/bash.html#Shell-Functions
使用以下语法声明函数:
Run Code Online (Sandbox Code Playgroud)[ function ] name () compound-command [ redirections ]这定义了一个名为name的shell函数.保留字功能是可选的.如果提供了功能保留字,则括号是可选的.
function省略括号是特定于bash的.所以为了更便携,不要使用它.