I would like to find out my environment variables in bash. Are they stored somewhere?
Asked
Active
Viewed 8.0k times
86
-
1Wow that was fast! I guess all the command do the trick. The export command gave me a lot of "declare -x" in front. Thanks guys! – Halil Dec 13 '10 at 17:59
-
3It was inappropriate to close this question as off topic. When programming on Linux, as I am doing at the moment, it is often useful to discover what the environmental variables are. Quite a lot of people have found this to be a useful question, including me. – Graham Asher Sep 22 '15 at 17:32
4 Answers
91
I am not sure if thats what you want, but try printenv
This will show you all your environment variables.
About where they are stored
Linux: where are environment variables stored?
How to set Shell Environment Variables
http://www.codecoffee.com/tipsforlinux/articles/030.html
Happy reading :-)
62
Just execute env in a terminal.
Example output:
$ env
TERM=xterm
SHELL=/bin/bash
USER=joksnet
USERNAME=joksnet
DESKTOP_SESSION=gnome
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PWD=/home/joksnet
GDM_KEYBOARD_LAYOUT=us
LANG=en_US.utf8
HOME=/home/joksnet
DISPLAY=:0.0
COLORTERM=gnome-terminal
_=/usr/bin/env
joksnet
- 2,255
- 15
- 18
12
Type export without any parameters.
Ronnie Howell
- 627
- 3
- 8
-
1Though `export` print some unneeded info (`declare -x`), I like that it sorts the variables by name – warvariuc Mar 24 '15 at 16:27
11
Or set:
SET(P) POSIX Programmer’s Manual SET(P)
NAME
set - set or unset options and positional parameters
SYNOPSIS
set [-abCefmnuvx][-h][-o option][argument...]
set [+abCefmnuvx][+h][+o option][argument...]
set -- [argument...]
set -o
set +o
DESCRIPTION
If no options or arguments are specified, set shall write the names and values of all shell variables in the collation sequence of the current locale. Each name
shall start on a separate line, using the format:
"%s=%s\n", <name>, <value>
The value string shall be written with appropriate quoting; see the description of shell quoting in Quoting . The output shall be suitable for reinput to the
shell, setting or resetting, as far as possible, the variables that are currently set; read-only variables cannot be reset.
karlphillip
- 89,883
- 35
- 240
- 408
-
9`env` or `printenv` are better. In bash, `set` will also print all your defined functions, which on a system like ubuntu, is a *very* long printout. – JimB Dec 13 '10 at 21:01