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.

6
  • 3
    This should be the accepted answer, as all others list more than just the name itself. In my case some variables contain multiline values which makes the other solutions not feasable.
    – Mene
    Commented Nov 9, 2017 at 15:20
  • 3
    A variant: compgen -v | while read line; do declare -p $line; done
    – Eljay
    Commented Dec 13, 2018 at 17:58
  • @Eljay what is the difference to just declare -p? Commented Jun 15, 2023 at 8:13
  • @DJCrashdummy • declare -p won't include things like BASH_COMMAND, BASH_SUBSHELL, COMP_WORDBREAKS, HISTCMD, LINENO, RANDOM, SECONDS.
    – Eljay
    Commented Jun 15, 2023 at 11:05
  • @Eljay well... at least for me declare -p "includes" resp. lists them all (and FUNCNAME additionally), but you are kind of right: the values are not shown and also values of arrays are not shown. do you know why this is? -- so IMHO your line is the most comprehensive way to do this, even with all values of arrays including indexes! Commented Jun 22, 2023 at 10:53