Join my Bash scripting course on Udemy 👀

See which environment variables are set with `printenv`

May 12, 2021  ‐ 1 min read

Data in your shell environment is either stored as a shell variable or an environment variable. Shell variables are globally set and readable within bash. Environment variables on the other hand are available to all processes or programs on your system.

You can use the printenv command in order to print the environment variables with their values. This printenv command will exclusively print environment variables.

$ printenv
COLORTERM=truecolor
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
DESKTOP_SESSION=ubuntu
DISPLAY=:0
EDITOR=vim
...

To print both the shell and environment variables you may use the set builtin available in bash. You may use the set builtin as well to change the value of shell attributes.

$ set
BASH=/usr/bin/bash
BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:globasciiranges:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=([0]="0")
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="5" [1]="0" [2]="17" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
BASH_VERSION='5.0.17(1)-release'
COLORTERM=truecolor
...