Timeline for How to list all variables names and their current values?
Current License: CC BY-SA 4.0
28 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 18, 2020 at 21:33 | comment | added | Colin Fraizer |
FWIW, I discovered this using: diff <( set -o posix; set | while read -r line; do printf "%s\n" "${line%%=*}"; done | sort) <(declare -p | while read -r _ flags line; do printf "%s\n" "${line%%=*}"; done | sort) to compare the outputs of each. Omitted variables were: BASHPID , BASH_ARGV0 , EPOCH{REALTIME,SECONDS} , FUNCNAME , HISTCMD , LINENO , OLDPWD , RANDOM , and SECONDS .
|
|
May 18, 2020 at 21:29 | comment | added | Colin Fraizer |
I like this answer for Bash, but the POSIX set omits some shell variables. You can get them all with declare -p | while read -r _ flags line; do printf "%s\n" "$line"; done .
|
|
Jul 26, 2019 at 19:08 | comment | added | Florin Andrei | This is incorrect. env or printenv only print environment variables. To get ALL VARIABLES declared in your current shell, use "declare -p" or "typeset -p". See another answer on this page. | |
S Oct 3, 2018 at 19:40 | history | edited | Fabby | CC BY-SA 4.0 |
Improved readability
|
S Oct 3, 2018 at 19:40 | history | suggested | CommunityBot | CC BY-SA 4.0 |
Added set option variant for ZSH
|
Oct 3, 2018 at 19:25 | review | Suggested edits | |||
S Oct 3, 2018 at 19:40 | |||||
Feb 19, 2018 at 16:35 | comment | added | Dereckson |
` -o posix` is bash only, not for sh
|
|
May 23, 2017 at 12:39 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Apr 13, 2017 at 12:37 | history | edited | CommunityBot |
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
|
|
Apr 13, 2017 at 12:24 | history | edited | CommunityBot |
replaced http://askubuntu.com/ with https://askubuntu.com/
|
|
S Jan 2, 2017 at 12:17 | history | suggested | jarno | CC BY-SA 3.0 |
Do not sort as it breaks showing environment variables set to have newline in its value. E.g. COMP_WORDBREAKS
|
Jan 2, 2017 at 10:54 | review | Suggested edits | |||
S Jan 2, 2017 at 12:17 | |||||
S Dec 25, 2016 at 19:30 | history | suggested | ВелоКастръ | CC BY-SA 3.0 |
Bit improved
|
Dec 25, 2016 at 19:05 | review | Suggested edits | |||
S Dec 25, 2016 at 19:30 | |||||
Aug 26, 2016 at 17:39 | comment | added | Bruno Bronosky |
To expand on @Rmano's reply to @Strapakowsky... This will not work unset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW , but this will unset MYNEWVARIABLE; export MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW , and this will unset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu printenv | grep MYNEW . Using export says "the variable I'm setting should be part of the environment that gets passed to processes, not just a variable in this shell." My third example says "the variable should be part of the environment that gets passed to THIS process, but not stick around afterward."
|
|
Apr 5, 2016 at 7:52 | comment | added | Craig Wayne | Works on OSX too | |
S Jul 30, 2015 at 15:56 | history | suggested | Dan Pritts | CC BY-SA 3.0 |
Add link to "environment variable vs. shell variable". Clarify that "your variables" are "shell" vars.
|
Jul 30, 2015 at 15:33 | comment | added | Dan Pritts |
printenv is an external command, so it only knows about (and prints) exported environment variables. set is an internal bash command, so it shows all the "shell variables" (unexported environment variables) as well as the exported environment variables.
|
|
Jul 30, 2015 at 15:32 | review | Suggested edits | |||
S Jul 30, 2015 at 15:56 | |||||
Feb 25, 2015 at 14:15 | review | Suggested edits | |||
Feb 25, 2015 at 15:48 | |||||
Jan 4, 2015 at 15:01 | comment | added | Sergiy Kolodyazhnyy |
if you simply execute set , it lists the variable created by you as well. Or do set | grep myvar
|
|
Aug 29, 2014 at 18:05 | history | edited | Lucio | CC BY-SA 3.0 |
removed obsolete paste ubuntu link
|
Oct 12, 2013 at 0:41 | comment | added | Rmano |
Probably you are seeing the difference between a shell variable and an environment variable. Try export MYNEWVARIABLE=Ubuntu and it will work as you expect.
|
|
May 31, 2013 at 5:16 | vote | accept | Strapakowsky | ||
Apr 1, 2013 at 14:50 | history | edited | Lucio | CC BY-SA 3.0 |
added information
|
Mar 30, 2013 at 3:30 | comment | added | Strapakowsky |
If I go to the terminal and write MYNEWVARIABLE=Ubuntu and execute printenv it doesn't show there. Why is that, and how do those others show up?
|
|
Mar 30, 2013 at 1:49 | history | edited | Lucio | CC BY-SA 3.0 |
added information
|
Mar 30, 2013 at 1:21 | history | answered | Lucio | CC BY-SA 3.0 |