Skip to main content
15 events
when toggle format what by license comment
Feb 9 at 18:26 comment added milahu declare -f prints all functions. declare -F prints all function names and their export status. declare -f someFunction prints some function
Jan 13, 2022 at 13:29 comment added geirha @Velkan that's a bit harder as there's no option with either declare or compgen that lists all but env vars, but you can get that list of variable names by grabbing all variable names (compgen -v) and removing the environment variables (compgen -e) from that. E.g. with comm -23 <(compgen -v) <(compgen -e)
Jan 13, 2022 at 7:49 comment added Velkan What if I want all variables except the environment?
Dec 21, 2020 at 4:27 comment added smac89 In zsh, use declare -p1 to prettify the printed variables for readability
May 22, 2020 at 13:55 comment added Colin Fraizer That is nice. Thanks! (Oddity: when called from top level—not within a function—declare -p includes FUNCNAME, but compgen -v does not. When called within a function, the output is identical.)
May 20, 2020 at 6:32 comment added geirha @ColinFraizer try compgen -v instead
May 18, 2020 at 21:42 comment added Colin Fraizer A useful addition, if you just want just the names and not the values: declare -p | while read -r _ flags line; do printf "%s\n" "${line%%=*}"; done. (Variables with values that contain embedded newlines, e.g. IFS, will add a blank line.)
Apr 19, 2020 at 10:53 comment added Alexey Vazhnov Works in ZSH too, thank you!
Feb 3, 2020 at 20:33 comment added geirha @maoizm If you want only the variable names and nothing else, it's easier to use compgen for that. compgen -e.
Feb 2, 2020 at 7:25 comment added maoizm for the sake of convenience the following bash oneliner prints names of all environment variables: declare -xp | grep --perl-regexp --only-match '(?<=^declare -x )[^=]+'
Oct 18, 2019 at 23:56 comment added WinEunuuchs2Unix I think this is what most people are looking for.
Jul 26, 2019 at 19:11 comment added Florin Andrei This is the correct answer.
Feb 7, 2018 at 16:50 comment added user359096 this is far neat-er solution than POSIXLY_CORRECT=1 set and it is also worthy of mention that declare is alias (in that context) for typeset, another bash builtin.
Apr 8, 2013 at 6:07 history edited geirha CC BY-SA 3.0
added 4 characters in body
Apr 4, 2013 at 20:28 history answered geirha CC BY-SA 3.0