On Mon, Jun 26, 2023, 00:25 Eli Schwartz <eschwart...@gmail.com> wrote:
> compgen is a useful builtin for inspecting information about the shell > context e.g. in scripts -- a good example of this is compgen -A function > or compgen -A variable. > > But it's not always available depending on how bash is built, which > results in people lacking confidence that it can / should be used in > scripts. See e.g. https://bugs.gentoo.org/909148 i read kerin s try to parse declare -p for me it works .. bash-5.2$ { FOO=$'\nBAR BAZ QUUX='; declare -p; } | while IFS=' =' read -r _ _ name _; do printf '%s\n' "$name"; done | grep QUUX bash-5.2$ echo $? 1 bash-5.2$ i ve experienced many changes in ' works ' bash code > Would it be possible to have a slightly more minimal version of it with > readline functionality and "currently inside programmable completions" > functionality stripped out, which just allows it to be used for general > environment introspection? > > An alternative for compgen -A function does exist -- declare -F in > combination with e.g. sed. Variables is harder since AFAICT the only way > to print all of them prints multiline values too (declare -p is similar > to declare -f, there is no declare -P similar to declare -F, using > ${!a@} to expand variable names does not work generically enough since > you need to specify a prefix -- ${!@} won't expand all of them). > subst directives only fullfill one thing alone per $@ , loop > -- > Eli Schwartz > >