使用括号而不是大括号定义bash函数体

该脚本演示了如何使用括号定义bash函数
带括号的经文.括号具有很好的制作效果
我想,在函数“local”中创建的环境变量
因为函数体是作为子shell执行的.输出是:
A=something
A=
B=something
B=something

问题是这是否允许定义函数的语法.

#!/bin/bash

foo() (
    export A=something
    echo A=$A
)

bar() {
    export B=something
    echo B=$B
}

foo
echo A=$A
bar
echo B=$B
是的,允许使用该语法.如 bash man page中所述,bash函数的定义是:
[ function ] name () compound-command [redirection]

更多描述(也来自手册页):

The body of the function is the compound command compound-command. That command is usually a list of commands between { and },but may be any command listed under Compound Commands above.

()和{}括号列表是复合命令.完整列表(再次从手册页,只是编辑到一个简单的列表):

A compound command is one of the following:

06001

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...