Finding all the ENV variables in Linux

Hello,

My question is, In Linux, how to list ALL the Environment variables (including UNSET variables).  The commands 'set' and 'env' are displaying the ENV variables which are defined.  I'm wondering how to see all the unset ENV variables, which could be useful for tuning certain stuffs in linux machine.

To make my question more clear, here I shown one example where I first try to list all the ENV related to 'history' command. In the first grep command, I can't see an unset ENV variable called "HISTTIMEFORMAT" getting displayed.  Later after I set that variable and export it, I could see it in the output and it altered the History command format. Like this how can I see other unset ENV variables. Please let me know.

[root@linuxmach ~]# set | grep -i hist
HISTFILE=/root/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor

[root@linuxmach ~]# export HISTTIMEFORMAT='%F %T '
[root@linuxmach ~]# set | grep -i hist
HISTFILE=/root/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
HISTTIMEFORMAT='%F %T '
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
_=history
[root@linuxmach ~]# history
.
.
<output truncated>
.
.
 1019  2012-08-18 07:00:04 cat environ
 1020  2012-08-18 07:00:34 cat status
 1021  2012-08-18 07:05:54 cd
 1022  2012-08-18 07:06:35 set
 1023  2012-08-18 07:06:47 set | grep -i hist
 1024  2012-08-18 07:07:05 export HISTTIMEFORMAT='%F %T '
 1025  2012-08-18 07:07:09 set | grep -i hist
 1026  2012-08-18 07:07:27 history
ashsysadAsked:
Who is Participating?
 
farzanjCommented:
It is really hard to see ALL the environment variables because a lot of these variables are not related to a particular shell -- they may be related to a particular application.  However if you know which shell you are going to use, you can see its variables and if you know which application you are going to use, you can see its variables.  The principle I use is based on the idea that variables do appear in the binaries of a program.  For instance if you want to see the variables of bash you can issue this command:

strings /bin/bash | grep -P '[A-Z]+'

Open in new window


Likewise if some variables are related to, say, vi, you can issue command like
strings `which vi` | grep -P '[A-Z]+'

Open in new window


Please note that there will be a lot of additional stuff and you will have to look for variables carefully.
0
 
omarfaridCommented:
If a variable is unset then you can not see it! It would be mentioned in the man page related to the command or tool or shell, etc.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
What do you want to tune? 'Certain stuffs' I don't understand. Unset variables don't exist and consume no memory, cpu, disk or other resources :-)
0
 
ozoCommented:
there are an infinite number of unset variables, as there are an infinite number of uninstalled and unwritten programs

You can list the HIST variables described in the bash documentation with
man bash | sed 's/[[:cntrl:]].//g' | egrep -x ' +HIST[[:alpha:]]*'
0
 
ashsysadAuthor Commented:
This is awesome !!  While posting this question, I wondered if am asking something stupid. Now with all your answers, I'm convinced that I have asked a sensible question.

I do found some useful ENV variables such as TIMEFORMAT, HISTCONTROL, HISTIGNORE etc, which I can reset in /etc/bash_profile.  

The following link seems to contain all the Bash variables explaining each:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html

Thanks a lot again !!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.