How to list all variables names and their current values?Where are all customized variables?'tools.jar' is...
Avoiding morning and evening handshakes
What is the purpose of easy combat scenarios that don't need resource expenditure?
Intern applicant asking for compensation equivalent to that of permanent employee
Can we use the stored gravitational potential energy of a building to produce power?
Can a person refuse a presidential pardon?
awk + sum all numbers
Can I write a book of my D&D game?
Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?
Why do no American passenger airlines still operate dedicated cargo flights?
Advice for a new journal editor
Would a National Army of mercenaries be a feasible idea?
Are there any modern advantages of a fire piston?
Using only 1s, make 29 with the minimum number of digits
Could a phylactery of a lich be a mirror or does it have to be a box?
Citing paywalled articles accessed via illegal web sharing
Is that a center tap tranformer just labelled differently?
Why do members of Congress in committee hearings ask witnesses the same question multiple times?
Table formatting top left corner caption
Why isn't there a non-conducting core wire for high-frequency coil applications
Do authors have to be politically correct in article-writing?
Why is mind meld hard for T'pol in Star Trek: Enterprise?
Cookies - Should the toggles be on?
Why avoid shared user accounts?
Why do neural networks need so many training examples to perform?
How to list all variables names and their current values?
Where are all customized variables?'tools.jar' is not in IDEA classpathEnvironment variable vs Shell variable, what's the difference?Sequence of scripts sourced upon loginchanging /etc/environment did not affect my environment variablesList all environment variables, and show if they are exported or notWhy aren't variables like $PS1 in printenv?What are the standard Environment variables ($) in Ubuntu?What is the difference between env, declare and compgen -v?When I open a terminal and type set I get a strange outputWhere to set environment variables for all usersHow to list all the PIDs and names of all the runing processesbash variable array names and getting valuesHow to set session-wide environment variables and PATH?List all environment variables, and show if they are exported or notList all chapter names and their descriptions from manpagesCopying certain files by partially matching their names to a list within a text fileHow can I find files with 7 characters (and no extension) in their names?How do I get a list of unique names and the sum of numbers from each row containing this name, with 1 command?System wide variables for both init scripts and system?
How to list all variables names and their current values?
Including not only $HOME
, $PWD
etc but any other you have defined.
command-line bash environment-variables
add a comment |
How to list all variables names and their current values?
Including not only $HOME
, $PWD
etc but any other you have defined.
command-line bash environment-variables
3
superuser.com/questions/420295/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 14:46
add a comment |
How to list all variables names and their current values?
Including not only $HOME
, $PWD
etc but any other you have defined.
command-line bash environment-variables
How to list all variables names and their current values?
Including not only $HOME
, $PWD
etc but any other you have defined.
command-line bash environment-variables
command-line bash environment-variables
edited Aug 24 '16 at 12:25
7ochem
1741212
1741212
asked Mar 30 '13 at 0:36
StrapakowskyStrapakowsky
3,819112638
3,819112638
3
superuser.com/questions/420295/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 14:46
add a comment |
3
superuser.com/questions/420295/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 14:46
3
3
superuser.com/questions/420295/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 14:46
superuser.com/questions/420295/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 14:46
add a comment |
9 Answers
9
active
oldest
votes
For bash: (the standard shell in Ubuntu)
Enter the following command in a terminal to print all the environment variables:
printenv
For further information about this command, read the printenv
man page.
To show a list including the "shell variables" you can enter the next command:
( set -o posix ; set ) | less
This will show you not only the shell variables, but the environment variables too.
For more information related with this topic read:
How to list variables declared in script in bash? from SO and
How to print all environment variables defined (but not necessarily
exported) in bash from
UnixSE
- Environment variable vs Shell variable, what's the difference?
For zsh: (an advanced shell)
Use the following command:
( setopt posixbuiltin; set; ) | less
For more information about ZSH options, see zshoptions
man page.
11
If I go to the terminal and writeMYNEWVARIABLE=Ubuntu
and executeprintenv
it doesn't show there. Why is that, and how do those others show up?
– Strapakowsky
Mar 30 '13 at 3:30
4
Probably you are seeing the difference between a shell variable and an environment variable. Tryexport MYNEWVARIABLE=Ubuntu
and it will work as you expect.
– Rmano
Oct 12 '13 at 0:41
3
if you simply executeset
, it lists the variable created by you as well. Or doset | grep myvar
– Sergiy Kolodyazhnyy
Jan 4 '15 at 15:01
4
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.
– Dan Pritts
Jul 30 '15 at 15:33
1
To expand on @Rmano's reply to @Strapakowsky... This will not workunset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, but this willunset MYNEWVARIABLE; export MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, and this willunset 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."
– Bruno Bronosky
Aug 26 '16 at 17:39
|
show 3 more comments
I know that this question is quite old and answered, but I think I can add a bit of useful information.
In all the methods described above, the procedure that is suggested is:
- launch a terminal
- show the environment variables using
env
, or
printenv
or whatever
The problem of these solutions are that you are seeing the environment variables of the shell that is running into the terminal. You are not seeing the environment variables available to an application run, for example, directly by the graphic interface.
This is noticeable if, for example, you use your ~/.profile
, or .bashrc
, or .zshenv
(depending on your shell) to modify the environment variables --- like the classic addition of directories to the path.
To see the environment variables available to the application started directly in the graphic environment, you can do the following (in Gnome Shell, I am sure there is an equivalent method in all the other DE):
- press Alt-F2
- run the command
xterm -e bash --noprofile --norc
You now have a terminal with a shell that did not add any environment variables. You can use env
here to list all your environment variables:
Obviously the new shell will have the environment variables added by the system files, but that variables should be available (by inheritance) to all programs in the system anyway.
I am posting this because it's the fourth time I have to search this trick again, checking my .pam_environment
file. So now I will find it faster (and in the process, I hope helping someone else...)
Requires you have a desktop environment, not useful for server CLI-only folk.
– K7AAY
Oct 21 '13 at 18:21
4
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot.
– Rmano
Oct 21 '13 at 20:36
2
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/…
– Gunnar Hjalmarsson
Jan 2 '14 at 17:06
Thanks. Did you recommendxterm -e bash --noprofile --norc
because the startup files are not read and executed when Ubuntu is started with graphical interface ? See askubuntu.com/q/1025845/1471
– Tim
Apr 17 '18 at 14:49
@Tim basically it's just a way to have a shell without anything more than the environment variables available to the graphic environment. A standard terminal will read (or re-read).bashrc
for example...
– Rmano
Apr 17 '18 at 15:06
add a comment |
You can see all variables with the declare
builtin.
declare -p
If you're only interested in environment variables, use
declare -xp
Run help declare
to see what the other options are.
this is far neat-er solution thanPOSIXLY_CORRECT=1 set
and it is also worthy of mention thatdeclare
isalias
(in that context) fortypeset
, another bash builtin.
– w17t
Feb 7 '18 at 16:50
add a comment |
To list the environment variables in terminal with CTRL+ALT+T you can use env
command.
for example :
[raja@localhost ~]$ env
XDG_VTNR=1
SSH_AGENT_PID=3671
XDG_SESSION_ID=3
HOSTNAME=localhost.localdomain
IMSETTINGS_INTEGRATE_DESKTOP=yes
GPG_AGENT_INFO=/home/raja/.gnupg/S.gpg-agent:3691:1
GLADE_PIXMAP_PATH=:
TERM=xterm-256color
SHELL=/bin/bash
XDG_MENU_PREFIX=xfce-
DESKTOP_STARTUP_ID=
HISTSIZE=1000
XDG_SESSION_COOKIE=0250277dd805498381e96c05d88068b0-1364679772.845276-1676152201
WINDOWID=65011716
GNOME_KEYRING_CONTROL=/home/raja/.cache/keyring-N3QoQ2
IMSETTINGS_MODULE=none
QT_GRAPHICSSYSTEM_CHECKED=1
USER=raja
etc.
hope that helps.
I've noticed that env misses some variables o_O. specifically after sourcing a VAR=VAL file.
– ThorSummoner
Aug 2 '17 at 19:43
1
@ThorSummoner The answer here might help stackoverflow.com/questions/15474650/…
– georaldc
Aug 14 '17 at 17:48
add a comment |
In bash using compgen:
compgen -v | while read line; do echo $line=${!line};done
1
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
Nov 9 '17 at 15:20
A variant:compgen -v | while read line; do declare -p $line; done
– Eljay
Dec 13 '18 at 17:58
add a comment |
env is a POSIX 7 way:
export asdf=qwer
env | grep asdf
Sample output:
asdf=qwer
It only shows exported variables: non-exported variables are not usually considered "environment variables".
Prefer that over printenv
, which is not POSIX. Both seem to do the same thing without arguments: https://unix.stackexchange.com/questions/123473/what-is-the-difference-between-env-and-printenv
Already mentioned two years ago: askubuntu.com/a/276162/158442
– muru
Nov 30 '15 at 15:00
@muru fair enough. Wish it had madeenv
more visible with better formatting, and I've added more info.
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 15:01
That's what editing is for.
– muru
Nov 30 '15 at 15:02
add a comment |
If you want a specific environment variable, rather than printing them all with printenv
, you can for example print it by doing echo "$PWD"
add a comment |
Most solutions here either print only environment variables, or have the drawback that env or (set -o posix; posix) do not print values in parseable form (try to print variable A=$'arnb'...).
Here is a function that will print all variables, one variable per line, in the POSIX escaped form:
function dump_vars {
local VARNAME
compgen -v | while read -r VARNAME; do
printf "$VARNAME=%qn" "${!VARNAME}"
done
}
Thanks to @tmgoblin for pointing out the use of compgen -v.
Excellent first answer! +1 Keep up the good work!
– Fabby
Dec 15 '18 at 16:29
add a comment |
printenv only lists exported variables,
CTRL+ALT+$
( "e$": complete-variable )
will list all variables.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f275965%2fhow-to-list-all-variables-names-and-their-current-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
For bash: (the standard shell in Ubuntu)
Enter the following command in a terminal to print all the environment variables:
printenv
For further information about this command, read the printenv
man page.
To show a list including the "shell variables" you can enter the next command:
( set -o posix ; set ) | less
This will show you not only the shell variables, but the environment variables too.
For more information related with this topic read:
How to list variables declared in script in bash? from SO and
How to print all environment variables defined (but not necessarily
exported) in bash from
UnixSE
- Environment variable vs Shell variable, what's the difference?
For zsh: (an advanced shell)
Use the following command:
( setopt posixbuiltin; set; ) | less
For more information about ZSH options, see zshoptions
man page.
11
If I go to the terminal and writeMYNEWVARIABLE=Ubuntu
and executeprintenv
it doesn't show there. Why is that, and how do those others show up?
– Strapakowsky
Mar 30 '13 at 3:30
4
Probably you are seeing the difference between a shell variable and an environment variable. Tryexport MYNEWVARIABLE=Ubuntu
and it will work as you expect.
– Rmano
Oct 12 '13 at 0:41
3
if you simply executeset
, it lists the variable created by you as well. Or doset | grep myvar
– Sergiy Kolodyazhnyy
Jan 4 '15 at 15:01
4
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.
– Dan Pritts
Jul 30 '15 at 15:33
1
To expand on @Rmano's reply to @Strapakowsky... This will not workunset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, but this willunset MYNEWVARIABLE; export MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, and this willunset 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."
– Bruno Bronosky
Aug 26 '16 at 17:39
|
show 3 more comments
For bash: (the standard shell in Ubuntu)
Enter the following command in a terminal to print all the environment variables:
printenv
For further information about this command, read the printenv
man page.
To show a list including the "shell variables" you can enter the next command:
( set -o posix ; set ) | less
This will show you not only the shell variables, but the environment variables too.
For more information related with this topic read:
How to list variables declared in script in bash? from SO and
How to print all environment variables defined (but not necessarily
exported) in bash from
UnixSE
- Environment variable vs Shell variable, what's the difference?
For zsh: (an advanced shell)
Use the following command:
( setopt posixbuiltin; set; ) | less
For more information about ZSH options, see zshoptions
man page.
11
If I go to the terminal and writeMYNEWVARIABLE=Ubuntu
and executeprintenv
it doesn't show there. Why is that, and how do those others show up?
– Strapakowsky
Mar 30 '13 at 3:30
4
Probably you are seeing the difference between a shell variable and an environment variable. Tryexport MYNEWVARIABLE=Ubuntu
and it will work as you expect.
– Rmano
Oct 12 '13 at 0:41
3
if you simply executeset
, it lists the variable created by you as well. Or doset | grep myvar
– Sergiy Kolodyazhnyy
Jan 4 '15 at 15:01
4
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.
– Dan Pritts
Jul 30 '15 at 15:33
1
To expand on @Rmano's reply to @Strapakowsky... This will not workunset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, but this willunset MYNEWVARIABLE; export MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, and this willunset 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."
– Bruno Bronosky
Aug 26 '16 at 17:39
|
show 3 more comments
For bash: (the standard shell in Ubuntu)
Enter the following command in a terminal to print all the environment variables:
printenv
For further information about this command, read the printenv
man page.
To show a list including the "shell variables" you can enter the next command:
( set -o posix ; set ) | less
This will show you not only the shell variables, but the environment variables too.
For more information related with this topic read:
How to list variables declared in script in bash? from SO and
How to print all environment variables defined (but not necessarily
exported) in bash from
UnixSE
- Environment variable vs Shell variable, what's the difference?
For zsh: (an advanced shell)
Use the following command:
( setopt posixbuiltin; set; ) | less
For more information about ZSH options, see zshoptions
man page.
For bash: (the standard shell in Ubuntu)
Enter the following command in a terminal to print all the environment variables:
printenv
For further information about this command, read the printenv
man page.
To show a list including the "shell variables" you can enter the next command:
( set -o posix ; set ) | less
This will show you not only the shell variables, but the environment variables too.
For more information related with this topic read:
How to list variables declared in script in bash? from SO and
How to print all environment variables defined (but not necessarily
exported) in bash from
UnixSE
- Environment variable vs Shell variable, what's the difference?
For zsh: (an advanced shell)
Use the following command:
( setopt posixbuiltin; set; ) | less
For more information about ZSH options, see zshoptions
man page.
edited Oct 3 '18 at 19:40
Fabby
26.9k1360161
26.9k1360161
answered Mar 30 '13 at 1:21
LucioLucio
12.6k2485161
12.6k2485161
11
If I go to the terminal and writeMYNEWVARIABLE=Ubuntu
and executeprintenv
it doesn't show there. Why is that, and how do those others show up?
– Strapakowsky
Mar 30 '13 at 3:30
4
Probably you are seeing the difference between a shell variable and an environment variable. Tryexport MYNEWVARIABLE=Ubuntu
and it will work as you expect.
– Rmano
Oct 12 '13 at 0:41
3
if you simply executeset
, it lists the variable created by you as well. Or doset | grep myvar
– Sergiy Kolodyazhnyy
Jan 4 '15 at 15:01
4
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.
– Dan Pritts
Jul 30 '15 at 15:33
1
To expand on @Rmano's reply to @Strapakowsky... This will not workunset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, but this willunset MYNEWVARIABLE; export MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, and this willunset 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."
– Bruno Bronosky
Aug 26 '16 at 17:39
|
show 3 more comments
11
If I go to the terminal and writeMYNEWVARIABLE=Ubuntu
and executeprintenv
it doesn't show there. Why is that, and how do those others show up?
– Strapakowsky
Mar 30 '13 at 3:30
4
Probably you are seeing the difference between a shell variable and an environment variable. Tryexport MYNEWVARIABLE=Ubuntu
and it will work as you expect.
– Rmano
Oct 12 '13 at 0:41
3
if you simply executeset
, it lists the variable created by you as well. Or doset | grep myvar
– Sergiy Kolodyazhnyy
Jan 4 '15 at 15:01
4
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.
– Dan Pritts
Jul 30 '15 at 15:33
1
To expand on @Rmano's reply to @Strapakowsky... This will not workunset MYNEWVARIABLE; MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, but this willunset MYNEWVARIABLE; export MYNEWVARIABLE=Ubuntu; printenv | grep MYNEW
, and this willunset 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."
– Bruno Bronosky
Aug 26 '16 at 17:39
11
11
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?– Strapakowsky
Mar 30 '13 at 3:30
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?– Strapakowsky
Mar 30 '13 at 3:30
4
4
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.– Rmano
Oct 12 '13 at 0:41
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.– Rmano
Oct 12 '13 at 0:41
3
3
if you simply execute
set
, it lists the variable created by you as well. Or do set | grep myvar
– Sergiy Kolodyazhnyy
Jan 4 '15 at 15:01
if you simply execute
set
, it lists the variable created by you as well. Or do set | grep myvar
– Sergiy Kolodyazhnyy
Jan 4 '15 at 15:01
4
4
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.– Dan Pritts
Jul 30 '15 at 15:33
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.– Dan Pritts
Jul 30 '15 at 15:33
1
1
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."– Bruno Bronosky
Aug 26 '16 at 17:39
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."– Bruno Bronosky
Aug 26 '16 at 17:39
|
show 3 more comments
I know that this question is quite old and answered, but I think I can add a bit of useful information.
In all the methods described above, the procedure that is suggested is:
- launch a terminal
- show the environment variables using
env
, or
printenv
or whatever
The problem of these solutions are that you are seeing the environment variables of the shell that is running into the terminal. You are not seeing the environment variables available to an application run, for example, directly by the graphic interface.
This is noticeable if, for example, you use your ~/.profile
, or .bashrc
, or .zshenv
(depending on your shell) to modify the environment variables --- like the classic addition of directories to the path.
To see the environment variables available to the application started directly in the graphic environment, you can do the following (in Gnome Shell, I am sure there is an equivalent method in all the other DE):
- press Alt-F2
- run the command
xterm -e bash --noprofile --norc
You now have a terminal with a shell that did not add any environment variables. You can use env
here to list all your environment variables:
Obviously the new shell will have the environment variables added by the system files, but that variables should be available (by inheritance) to all programs in the system anyway.
I am posting this because it's the fourth time I have to search this trick again, checking my .pam_environment
file. So now I will find it faster (and in the process, I hope helping someone else...)
Requires you have a desktop environment, not useful for server CLI-only folk.
– K7AAY
Oct 21 '13 at 18:21
4
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot.
– Rmano
Oct 21 '13 at 20:36
2
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/…
– Gunnar Hjalmarsson
Jan 2 '14 at 17:06
Thanks. Did you recommendxterm -e bash --noprofile --norc
because the startup files are not read and executed when Ubuntu is started with graphical interface ? See askubuntu.com/q/1025845/1471
– Tim
Apr 17 '18 at 14:49
@Tim basically it's just a way to have a shell without anything more than the environment variables available to the graphic environment. A standard terminal will read (or re-read).bashrc
for example...
– Rmano
Apr 17 '18 at 15:06
add a comment |
I know that this question is quite old and answered, but I think I can add a bit of useful information.
In all the methods described above, the procedure that is suggested is:
- launch a terminal
- show the environment variables using
env
, or
printenv
or whatever
The problem of these solutions are that you are seeing the environment variables of the shell that is running into the terminal. You are not seeing the environment variables available to an application run, for example, directly by the graphic interface.
This is noticeable if, for example, you use your ~/.profile
, or .bashrc
, or .zshenv
(depending on your shell) to modify the environment variables --- like the classic addition of directories to the path.
To see the environment variables available to the application started directly in the graphic environment, you can do the following (in Gnome Shell, I am sure there is an equivalent method in all the other DE):
- press Alt-F2
- run the command
xterm -e bash --noprofile --norc
You now have a terminal with a shell that did not add any environment variables. You can use env
here to list all your environment variables:
Obviously the new shell will have the environment variables added by the system files, but that variables should be available (by inheritance) to all programs in the system anyway.
I am posting this because it's the fourth time I have to search this trick again, checking my .pam_environment
file. So now I will find it faster (and in the process, I hope helping someone else...)
Requires you have a desktop environment, not useful for server CLI-only folk.
– K7AAY
Oct 21 '13 at 18:21
4
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot.
– Rmano
Oct 21 '13 at 20:36
2
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/…
– Gunnar Hjalmarsson
Jan 2 '14 at 17:06
Thanks. Did you recommendxterm -e bash --noprofile --norc
because the startup files are not read and executed when Ubuntu is started with graphical interface ? See askubuntu.com/q/1025845/1471
– Tim
Apr 17 '18 at 14:49
@Tim basically it's just a way to have a shell without anything more than the environment variables available to the graphic environment. A standard terminal will read (or re-read).bashrc
for example...
– Rmano
Apr 17 '18 at 15:06
add a comment |
I know that this question is quite old and answered, but I think I can add a bit of useful information.
In all the methods described above, the procedure that is suggested is:
- launch a terminal
- show the environment variables using
env
, or
printenv
or whatever
The problem of these solutions are that you are seeing the environment variables of the shell that is running into the terminal. You are not seeing the environment variables available to an application run, for example, directly by the graphic interface.
This is noticeable if, for example, you use your ~/.profile
, or .bashrc
, or .zshenv
(depending on your shell) to modify the environment variables --- like the classic addition of directories to the path.
To see the environment variables available to the application started directly in the graphic environment, you can do the following (in Gnome Shell, I am sure there is an equivalent method in all the other DE):
- press Alt-F2
- run the command
xterm -e bash --noprofile --norc
You now have a terminal with a shell that did not add any environment variables. You can use env
here to list all your environment variables:
Obviously the new shell will have the environment variables added by the system files, but that variables should be available (by inheritance) to all programs in the system anyway.
I am posting this because it's the fourth time I have to search this trick again, checking my .pam_environment
file. So now I will find it faster (and in the process, I hope helping someone else...)
I know that this question is quite old and answered, but I think I can add a bit of useful information.
In all the methods described above, the procedure that is suggested is:
- launch a terminal
- show the environment variables using
env
, or
printenv
or whatever
The problem of these solutions are that you are seeing the environment variables of the shell that is running into the terminal. You are not seeing the environment variables available to an application run, for example, directly by the graphic interface.
This is noticeable if, for example, you use your ~/.profile
, or .bashrc
, or .zshenv
(depending on your shell) to modify the environment variables --- like the classic addition of directories to the path.
To see the environment variables available to the application started directly in the graphic environment, you can do the following (in Gnome Shell, I am sure there is an equivalent method in all the other DE):
- press Alt-F2
- run the command
xterm -e bash --noprofile --norc
You now have a terminal with a shell that did not add any environment variables. You can use env
here to list all your environment variables:
Obviously the new shell will have the environment variables added by the system files, but that variables should be available (by inheritance) to all programs in the system anyway.
I am posting this because it's the fourth time I have to search this trick again, checking my .pam_environment
file. So now I will find it faster (and in the process, I hope helping someone else...)
edited Dec 25 '16 at 20:33
Byte Commander
65.4k27178302
65.4k27178302
answered Oct 12 '13 at 0:37
RmanoRmano
25.4k879147
25.4k879147
Requires you have a desktop environment, not useful for server CLI-only folk.
– K7AAY
Oct 21 '13 at 18:21
4
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot.
– Rmano
Oct 21 '13 at 20:36
2
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/…
– Gunnar Hjalmarsson
Jan 2 '14 at 17:06
Thanks. Did you recommendxterm -e bash --noprofile --norc
because the startup files are not read and executed when Ubuntu is started with graphical interface ? See askubuntu.com/q/1025845/1471
– Tim
Apr 17 '18 at 14:49
@Tim basically it's just a way to have a shell without anything more than the environment variables available to the graphic environment. A standard terminal will read (or re-read).bashrc
for example...
– Rmano
Apr 17 '18 at 15:06
add a comment |
Requires you have a desktop environment, not useful for server CLI-only folk.
– K7AAY
Oct 21 '13 at 18:21
4
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot.
– Rmano
Oct 21 '13 at 20:36
2
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/…
– Gunnar Hjalmarsson
Jan 2 '14 at 17:06
Thanks. Did you recommendxterm -e bash --noprofile --norc
because the startup files are not read and executed when Ubuntu is started with graphical interface ? See askubuntu.com/q/1025845/1471
– Tim
Apr 17 '18 at 14:49
@Tim basically it's just a way to have a shell without anything more than the environment variables available to the graphic environment. A standard terminal will read (or re-read).bashrc
for example...
– Rmano
Apr 17 '18 at 15:06
Requires you have a desktop environment, not useful for server CLI-only folk.
– K7AAY
Oct 21 '13 at 18:21
Requires you have a desktop environment, not useful for server CLI-only folk.
– K7AAY
Oct 21 '13 at 18:21
4
4
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot.
– Rmano
Oct 21 '13 at 20:36
Yes --- but then for CLI only the previous answer is ok. I was just pointing out that sometime you need to check environment variables available to application started by the graphical environment, which is not the same set you see when you start a terminal in it. For example, if you are trying to understand why your Kile app can't compile a LaTeX file, while in a terminal you can, the trick I posted here will help a lot.
– Rmano
Oct 21 '13 at 20:36
2
2
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/…
– Gunnar Hjalmarsson
Jan 2 '14 at 17:06
Thanks for a very useful answer! I just linked to it from help.ubuntu.com/community/…
– Gunnar Hjalmarsson
Jan 2 '14 at 17:06
Thanks. Did you recommend
xterm -e bash --noprofile --norc
because the startup files are not read and executed when Ubuntu is started with graphical interface ? See askubuntu.com/q/1025845/1471– Tim
Apr 17 '18 at 14:49
Thanks. Did you recommend
xterm -e bash --noprofile --norc
because the startup files are not read and executed when Ubuntu is started with graphical interface ? See askubuntu.com/q/1025845/1471– Tim
Apr 17 '18 at 14:49
@Tim basically it's just a way to have a shell without anything more than the environment variables available to the graphic environment. A standard terminal will read (or re-read)
.bashrc
for example...– Rmano
Apr 17 '18 at 15:06
@Tim basically it's just a way to have a shell without anything more than the environment variables available to the graphic environment. A standard terminal will read (or re-read)
.bashrc
for example...– Rmano
Apr 17 '18 at 15:06
add a comment |
You can see all variables with the declare
builtin.
declare -p
If you're only interested in environment variables, use
declare -xp
Run help declare
to see what the other options are.
this is far neat-er solution thanPOSIXLY_CORRECT=1 set
and it is also worthy of mention thatdeclare
isalias
(in that context) fortypeset
, another bash builtin.
– w17t
Feb 7 '18 at 16:50
add a comment |
You can see all variables with the declare
builtin.
declare -p
If you're only interested in environment variables, use
declare -xp
Run help declare
to see what the other options are.
this is far neat-er solution thanPOSIXLY_CORRECT=1 set
and it is also worthy of mention thatdeclare
isalias
(in that context) fortypeset
, another bash builtin.
– w17t
Feb 7 '18 at 16:50
add a comment |
You can see all variables with the declare
builtin.
declare -p
If you're only interested in environment variables, use
declare -xp
Run help declare
to see what the other options are.
You can see all variables with the declare
builtin.
declare -p
If you're only interested in environment variables, use
declare -xp
Run help declare
to see what the other options are.
edited Apr 8 '13 at 6:07
answered Apr 4 '13 at 20:28
geirhageirha
31.1k95760
31.1k95760
this is far neat-er solution thanPOSIXLY_CORRECT=1 set
and it is also worthy of mention thatdeclare
isalias
(in that context) fortypeset
, another bash builtin.
– w17t
Feb 7 '18 at 16:50
add a comment |
this is far neat-er solution thanPOSIXLY_CORRECT=1 set
and it is also worthy of mention thatdeclare
isalias
(in that context) fortypeset
, another bash builtin.
– w17t
Feb 7 '18 at 16:50
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.– w17t
Feb 7 '18 at 16:50
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.– w17t
Feb 7 '18 at 16:50
add a comment |
To list the environment variables in terminal with CTRL+ALT+T you can use env
command.
for example :
[raja@localhost ~]$ env
XDG_VTNR=1
SSH_AGENT_PID=3671
XDG_SESSION_ID=3
HOSTNAME=localhost.localdomain
IMSETTINGS_INTEGRATE_DESKTOP=yes
GPG_AGENT_INFO=/home/raja/.gnupg/S.gpg-agent:3691:1
GLADE_PIXMAP_PATH=:
TERM=xterm-256color
SHELL=/bin/bash
XDG_MENU_PREFIX=xfce-
DESKTOP_STARTUP_ID=
HISTSIZE=1000
XDG_SESSION_COOKIE=0250277dd805498381e96c05d88068b0-1364679772.845276-1676152201
WINDOWID=65011716
GNOME_KEYRING_CONTROL=/home/raja/.cache/keyring-N3QoQ2
IMSETTINGS_MODULE=none
QT_GRAPHICSSYSTEM_CHECKED=1
USER=raja
etc.
hope that helps.
I've noticed that env misses some variables o_O. specifically after sourcing a VAR=VAL file.
– ThorSummoner
Aug 2 '17 at 19:43
1
@ThorSummoner The answer here might help stackoverflow.com/questions/15474650/…
– georaldc
Aug 14 '17 at 17:48
add a comment |
To list the environment variables in terminal with CTRL+ALT+T you can use env
command.
for example :
[raja@localhost ~]$ env
XDG_VTNR=1
SSH_AGENT_PID=3671
XDG_SESSION_ID=3
HOSTNAME=localhost.localdomain
IMSETTINGS_INTEGRATE_DESKTOP=yes
GPG_AGENT_INFO=/home/raja/.gnupg/S.gpg-agent:3691:1
GLADE_PIXMAP_PATH=:
TERM=xterm-256color
SHELL=/bin/bash
XDG_MENU_PREFIX=xfce-
DESKTOP_STARTUP_ID=
HISTSIZE=1000
XDG_SESSION_COOKIE=0250277dd805498381e96c05d88068b0-1364679772.845276-1676152201
WINDOWID=65011716
GNOME_KEYRING_CONTROL=/home/raja/.cache/keyring-N3QoQ2
IMSETTINGS_MODULE=none
QT_GRAPHICSSYSTEM_CHECKED=1
USER=raja
etc.
hope that helps.
I've noticed that env misses some variables o_O. specifically after sourcing a VAR=VAL file.
– ThorSummoner
Aug 2 '17 at 19:43
1
@ThorSummoner The answer here might help stackoverflow.com/questions/15474650/…
– georaldc
Aug 14 '17 at 17:48
add a comment |
To list the environment variables in terminal with CTRL+ALT+T you can use env
command.
for example :
[raja@localhost ~]$ env
XDG_VTNR=1
SSH_AGENT_PID=3671
XDG_SESSION_ID=3
HOSTNAME=localhost.localdomain
IMSETTINGS_INTEGRATE_DESKTOP=yes
GPG_AGENT_INFO=/home/raja/.gnupg/S.gpg-agent:3691:1
GLADE_PIXMAP_PATH=:
TERM=xterm-256color
SHELL=/bin/bash
XDG_MENU_PREFIX=xfce-
DESKTOP_STARTUP_ID=
HISTSIZE=1000
XDG_SESSION_COOKIE=0250277dd805498381e96c05d88068b0-1364679772.845276-1676152201
WINDOWID=65011716
GNOME_KEYRING_CONTROL=/home/raja/.cache/keyring-N3QoQ2
IMSETTINGS_MODULE=none
QT_GRAPHICSSYSTEM_CHECKED=1
USER=raja
etc.
hope that helps.
To list the environment variables in terminal with CTRL+ALT+T you can use env
command.
for example :
[raja@localhost ~]$ env
XDG_VTNR=1
SSH_AGENT_PID=3671
XDG_SESSION_ID=3
HOSTNAME=localhost.localdomain
IMSETTINGS_INTEGRATE_DESKTOP=yes
GPG_AGENT_INFO=/home/raja/.gnupg/S.gpg-agent:3691:1
GLADE_PIXMAP_PATH=:
TERM=xterm-256color
SHELL=/bin/bash
XDG_MENU_PREFIX=xfce-
DESKTOP_STARTUP_ID=
HISTSIZE=1000
XDG_SESSION_COOKIE=0250277dd805498381e96c05d88068b0-1364679772.845276-1676152201
WINDOWID=65011716
GNOME_KEYRING_CONTROL=/home/raja/.cache/keyring-N3QoQ2
IMSETTINGS_MODULE=none
QT_GRAPHICSSYSTEM_CHECKED=1
USER=raja
etc.
hope that helps.
answered Mar 30 '13 at 16:41
rɑːdʒɑrɑːdʒɑ
58.2k85218302
58.2k85218302
I've noticed that env misses some variables o_O. specifically after sourcing a VAR=VAL file.
– ThorSummoner
Aug 2 '17 at 19:43
1
@ThorSummoner The answer here might help stackoverflow.com/questions/15474650/…
– georaldc
Aug 14 '17 at 17:48
add a comment |
I've noticed that env misses some variables o_O. specifically after sourcing a VAR=VAL file.
– ThorSummoner
Aug 2 '17 at 19:43
1
@ThorSummoner The answer here might help stackoverflow.com/questions/15474650/…
– georaldc
Aug 14 '17 at 17:48
I've noticed that env misses some variables o_O. specifically after sourcing a VAR=VAL file.
– ThorSummoner
Aug 2 '17 at 19:43
I've noticed that env misses some variables o_O. specifically after sourcing a VAR=VAL file.
– ThorSummoner
Aug 2 '17 at 19:43
1
1
@ThorSummoner The answer here might help stackoverflow.com/questions/15474650/…
– georaldc
Aug 14 '17 at 17:48
@ThorSummoner The answer here might help stackoverflow.com/questions/15474650/…
– georaldc
Aug 14 '17 at 17:48
add a comment |
In bash using compgen:
compgen -v | while read line; do echo $line=${!line};done
1
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
Nov 9 '17 at 15:20
A variant:compgen -v | while read line; do declare -p $line; done
– Eljay
Dec 13 '18 at 17:58
add a comment |
In bash using compgen:
compgen -v | while read line; do echo $line=${!line};done
1
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
Nov 9 '17 at 15:20
A variant:compgen -v | while read line; do declare -p $line; done
– Eljay
Dec 13 '18 at 17:58
add a comment |
In bash using compgen:
compgen -v | while read line; do echo $line=${!line};done
In bash using compgen:
compgen -v | while read line; do echo $line=${!line};done
edited Apr 11 '14 at 21:07
Seth♦
34.8k27112165
34.8k27112165
answered Apr 11 '14 at 20:53
tmgoblintmgoblin
491
491
1
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
Nov 9 '17 at 15:20
A variant:compgen -v | while read line; do declare -p $line; done
– Eljay
Dec 13 '18 at 17:58
add a comment |
1
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
Nov 9 '17 at 15:20
A variant:compgen -v | while read line; do declare -p $line; done
– Eljay
Dec 13 '18 at 17:58
1
1
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
Nov 9 '17 at 15:20
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
Nov 9 '17 at 15:20
A variant:
compgen -v | while read line; do declare -p $line; done
– Eljay
Dec 13 '18 at 17:58
A variant:
compgen -v | while read line; do declare -p $line; done
– Eljay
Dec 13 '18 at 17:58
add a comment |
env is a POSIX 7 way:
export asdf=qwer
env | grep asdf
Sample output:
asdf=qwer
It only shows exported variables: non-exported variables are not usually considered "environment variables".
Prefer that over printenv
, which is not POSIX. Both seem to do the same thing without arguments: https://unix.stackexchange.com/questions/123473/what-is-the-difference-between-env-and-printenv
Already mentioned two years ago: askubuntu.com/a/276162/158442
– muru
Nov 30 '15 at 15:00
@muru fair enough. Wish it had madeenv
more visible with better formatting, and I've added more info.
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 15:01
That's what editing is for.
– muru
Nov 30 '15 at 15:02
add a comment |
env is a POSIX 7 way:
export asdf=qwer
env | grep asdf
Sample output:
asdf=qwer
It only shows exported variables: non-exported variables are not usually considered "environment variables".
Prefer that over printenv
, which is not POSIX. Both seem to do the same thing without arguments: https://unix.stackexchange.com/questions/123473/what-is-the-difference-between-env-and-printenv
Already mentioned two years ago: askubuntu.com/a/276162/158442
– muru
Nov 30 '15 at 15:00
@muru fair enough. Wish it had madeenv
more visible with better formatting, and I've added more info.
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 15:01
That's what editing is for.
– muru
Nov 30 '15 at 15:02
add a comment |
env is a POSIX 7 way:
export asdf=qwer
env | grep asdf
Sample output:
asdf=qwer
It only shows exported variables: non-exported variables are not usually considered "environment variables".
Prefer that over printenv
, which is not POSIX. Both seem to do the same thing without arguments: https://unix.stackexchange.com/questions/123473/what-is-the-difference-between-env-and-printenv
env is a POSIX 7 way:
export asdf=qwer
env | grep asdf
Sample output:
asdf=qwer
It only shows exported variables: non-exported variables are not usually considered "environment variables".
Prefer that over printenv
, which is not POSIX. Both seem to do the same thing without arguments: https://unix.stackexchange.com/questions/123473/what-is-the-difference-between-env-and-printenv
edited Apr 13 '17 at 12:37
Community♦
1
1
answered Nov 30 '15 at 14:31
Ciro Santilli 新疆改造中心 六四事件 法轮功Ciro Santilli 新疆改造中心 六四事件 法轮功
9,83944550
9,83944550
Already mentioned two years ago: askubuntu.com/a/276162/158442
– muru
Nov 30 '15 at 15:00
@muru fair enough. Wish it had madeenv
more visible with better formatting, and I've added more info.
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 15:01
That's what editing is for.
– muru
Nov 30 '15 at 15:02
add a comment |
Already mentioned two years ago: askubuntu.com/a/276162/158442
– muru
Nov 30 '15 at 15:00
@muru fair enough. Wish it had madeenv
more visible with better formatting, and I've added more info.
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 15:01
That's what editing is for.
– muru
Nov 30 '15 at 15:02
Already mentioned two years ago: askubuntu.com/a/276162/158442
– muru
Nov 30 '15 at 15:00
Already mentioned two years ago: askubuntu.com/a/276162/158442
– muru
Nov 30 '15 at 15:00
@muru fair enough. Wish it had made
env
more visible with better formatting, and I've added more info.– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 15:01
@muru fair enough. Wish it had made
env
more visible with better formatting, and I've added more info.– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 15:01
That's what editing is for.
– muru
Nov 30 '15 at 15:02
That's what editing is for.
– muru
Nov 30 '15 at 15:02
add a comment |
If you want a specific environment variable, rather than printing them all with printenv
, you can for example print it by doing echo "$PWD"
add a comment |
If you want a specific environment variable, rather than printing them all with printenv
, you can for example print it by doing echo "$PWD"
add a comment |
If you want a specific environment variable, rather than printing them all with printenv
, you can for example print it by doing echo "$PWD"
If you want a specific environment variable, rather than printing them all with printenv
, you can for example print it by doing echo "$PWD"
answered Jan 8 '18 at 14:13
inigo333inigo333
1113
1113
add a comment |
add a comment |
Most solutions here either print only environment variables, or have the drawback that env or (set -o posix; posix) do not print values in parseable form (try to print variable A=$'arnb'...).
Here is a function that will print all variables, one variable per line, in the POSIX escaped form:
function dump_vars {
local VARNAME
compgen -v | while read -r VARNAME; do
printf "$VARNAME=%qn" "${!VARNAME}"
done
}
Thanks to @tmgoblin for pointing out the use of compgen -v.
Excellent first answer! +1 Keep up the good work!
– Fabby
Dec 15 '18 at 16:29
add a comment |
Most solutions here either print only environment variables, or have the drawback that env or (set -o posix; posix) do not print values in parseable form (try to print variable A=$'arnb'...).
Here is a function that will print all variables, one variable per line, in the POSIX escaped form:
function dump_vars {
local VARNAME
compgen -v | while read -r VARNAME; do
printf "$VARNAME=%qn" "${!VARNAME}"
done
}
Thanks to @tmgoblin for pointing out the use of compgen -v.
Excellent first answer! +1 Keep up the good work!
– Fabby
Dec 15 '18 at 16:29
add a comment |
Most solutions here either print only environment variables, or have the drawback that env or (set -o posix; posix) do not print values in parseable form (try to print variable A=$'arnb'...).
Here is a function that will print all variables, one variable per line, in the POSIX escaped form:
function dump_vars {
local VARNAME
compgen -v | while read -r VARNAME; do
printf "$VARNAME=%qn" "${!VARNAME}"
done
}
Thanks to @tmgoblin for pointing out the use of compgen -v.
Most solutions here either print only environment variables, or have the drawback that env or (set -o posix; posix) do not print values in parseable form (try to print variable A=$'arnb'...).
Here is a function that will print all variables, one variable per line, in the POSIX escaped form:
function dump_vars {
local VARNAME
compgen -v | while read -r VARNAME; do
printf "$VARNAME=%qn" "${!VARNAME}"
done
}
Thanks to @tmgoblin for pointing out the use of compgen -v.
answered Dec 15 '18 at 15:58
Ján LalinskýJán Lalinský
1112
1112
Excellent first answer! +1 Keep up the good work!
– Fabby
Dec 15 '18 at 16:29
add a comment |
Excellent first answer! +1 Keep up the good work!
– Fabby
Dec 15 '18 at 16:29
Excellent first answer! +1 Keep up the good work!
– Fabby
Dec 15 '18 at 16:29
Excellent first answer! +1 Keep up the good work!
– Fabby
Dec 15 '18 at 16:29
add a comment |
printenv only lists exported variables,
CTRL+ALT+$
( "e$": complete-variable )
will list all variables.
add a comment |
printenv only lists exported variables,
CTRL+ALT+$
( "e$": complete-variable )
will list all variables.
add a comment |
printenv only lists exported variables,
CTRL+ALT+$
( "e$": complete-variable )
will list all variables.
printenv only lists exported variables,
CTRL+ALT+$
( "e$": complete-variable )
will list all variables.
answered 7 mins ago
user1133275user1133275
18410
18410
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f275965%2fhow-to-list-all-variables-names-and-their-current-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
superuser.com/questions/420295/…
– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 30 '15 at 14:46