Linux / Unix: Bash Shell See All Exported Variables and Functions

How do I see a list of all exported variables and functions under Unix bash shell?

The export command makes your local variables global. The syntax is as follows:

export PATH=$PATH:/usr/local/bin:~/bin
export EDITOR=/usr/local/bin/vim
export SHELL=/bin/ksh
export LANG=En_US
export PAGER=/usr/local/bin/most

To make your local shell variables global automatically, export them in your ~/.profile or ~/.bash_profile file under Unix like operating systems. To see a list of all exported variables and functions pass the -p option to the export command:

export -p
export -p | grep  something
export -p | less
export -p | more

Sample outputs:

DISPLAY=unix:0
EDITOR=vim
HISTFILE=/home/vivek/.bash_history
HISTSIZE=1000
HOME=/home/vivek
LANG=En_IN
LOGNAME=vivek
MAIL=/usr/mail/vivek
MAILCHECK=0
PWD=/home/vivek
SHELL=/bin/bash

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • joebob May 12, 2012 @ 1:57

    ‘set’ will display all defined variables and functions in your current session.

  • Antonius May 23, 2012 @ 5:24

    Can i use that for setting JAVA_HOME at bash profile ? How to make it permanent ?

  • thoran May 30, 2012 @ 0:11

    There’s also `env`, or `env | sort` if one desires sorted output as per export -p.

  • LaGunA Jun 28, 2012 @ 7:33

    @Antonius: Yes, of course you can. Add the following lines:
    export JAVA_HOME=/path/to/your/java/installation
    export PATH=JAVA_HOME/bin:$PATH
    to ~/.bash_profile (or ~/.bashrc) and you’re done! :)

  • Leslie Satenstein Mar 10, 2014 @ 1:22

    undo an export
    a parameter was exported to the current shell.

    I use a few different scripts that follow using that exported parameter
    Now I want to remove that exported variable.

    Aside from logging out, is the only way to remove it to set it to a null string?

    • 🐧 Nix Craft Mar 10, 2014 @ 4:36

      Try unset command:
      unset VAR_NAME
      For example:

      export FOO=bar
      echo $FOO
      bash
      echo $FOO
      exit
      unset FOO
      echo $FOO
      

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum