列出Bash中定义的函数 [英] Listing defined functions in Bash
本文介绍了列出Bash中定义的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用bash编写一些代码,这些代码使用自省功能来选择要调用的适当函数.
I'm trying to write some code in bash which uses introspection to select the appropriate function to call.
确定候选人需要知道定义了哪些职能.仅使用参数扩展即可在bash中列出定义的变量很容易:
Determining the candidates requires knowing which functions are defined. It's easy to list defined variables in bash using only parameter expansion:
$ prefix_foo="one"
$ prefix_bar="two"
$ echo "${!prefix_*}"
prefix_bar prefix_foo
但是,对 function 执行此操作似乎需要过滤set的输出-一种更加随意的方法.
However, doing this for functions appears to require filtering the output of set -- a much more haphazard approach.
有正确的方法吗?
推荐答案
compgen :
compgen -A function # compgen is a shell builtin
这篇关于列出Bash中定义的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文