Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • I'd only expect that to work with the bash shell and only if it's not in POSIX mode and variable names and values don't contain newline characters and name doesn't contain spaces. The OP specifically asked for a POSIX shell solution. If you're going to use a bash-specific solution, you might as well use compgen -e Commented Aug 17, 2023 at 19:24
  • This works for the case where variable values have newlines & spaces, that's the case that I wrote this for... I didn't realize you could have newlines in a variable name. It is an example for bash, because the OP provided an example for bash that didn't work, and this snippet does. Commented Sep 7, 2023 at 1:50