Ala*_*zin 3 bash bash-functions
我知道我可以这样做:
function foo() { echo "foo"; }; export -f foo
Run Code Online (Sandbox Code Playgroud)
但是我可以在不重复函数名称的情况下做到这一点吗?
set -a # or: set -o allexport
# will be exported:
foo () {
echo foo
}
set +a # or: set +o allexport
# will not be exported:
bar () {
echo bar
}
Run Code Online (Sandbox Code Playgroud)
在中设置allexportshell 选项bash将导出您在设置选项时定义的所有函数。您可以为需要它的文件部分设置此选项,然后取消设置。
请注意,这也会影响已定义的变量(它们会自动转换为环境变量),但不会影响函数定义中的变量。
| 归档时间: |
|
| 查看次数: |
47 次 |
| 最近记录: |