linux - bash - 编写函数语法的两种方式

标签 linux bash function sh ksh

在 bash 中我们可以写函数,但实际上我们有两种方式(两种语法),

请指教

example1example2 有什么区别

或者也许没有任何区别?

 function I_love_function

 {

  .
  .

 }

I_love_function ()

{

  .
  .
}

如何调用函数I_love_function

最佳答案

发件人:http://www.gnu.org/software/bash/manual/bashref.html#Shell-Functions

Functions are declared using this syntax:

name () compound-command [ redirections ] 
or 
function name [()] compound-command [ redirections ]

This defines a shell function named name. The reserved word function is optional. If the function reserved word is supplied, the parentheses are optional.

关于linux - bash - 编写函数语法的两种方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23994072/

相关文章:

linux - 在 OpenWRT Linux 上使用 C/C++ 通过 IP 从串口转发字节

python - 配置失败: C compiler cannot create executables(configure: exit 77)有什么问题

python - 以数组格式返回该位置硬币所需的硬币数量

function - 自定义函数中存储的值

linux - Echo -e 在我的脚本中不起作用

javascript - 如何处理只被一个函数使用的函数

c - 如何编译这个C程序?

linux - Yum 无法在 CentOS 6 上更新

bash - 在 Mac OSX 上从源代码编译 vim 并出现 'shell returned 127' 错误?

linux - 意外标记附近的语法错误 `}'