Sunday, August 19, 2012

Environment variables in Linux

On a Linux system, we can view the Environment variables that are set and exported using 3 built-in commands: 
'set', 'env' & 'export -p'.

Ever wondered how can we see the other 'unset' environment variables belongs to Bash shell or some command or tool ?

The technique that I follow is to look in 2 places: One in the Binaries of the program which the application uses and other in the MAN page.

To view all the printable strings in a Bash shell:  # strings /bin/bash | grep -P '[A-Z]+'
In this output, there will be a lot of additional stuff and you will have to look for environment variables carefully

To print all the ENV variables related to 'history' command:

# man bash | sed 's/[[:cntrl:]].//g' | egrep -x ' +HIST[[:alpha:]]*'
       HISTCMD
       HISTCONTROL
       HISTFILE
       HISTFILESIZE
       HISTIGNORE
       HISTSIZE
       HISTTIMEFORMAT

A URL that contains all the Bash variables explaining each:

1 comment: