How to list all environment variables?

QuestionsQuestions8 SkillsProDec, 13 2025
0257

That's an excellent question, and it's very relevant to understanding your system's environment!

You can list all currently set environment variables in your shell using a few different commands:

  1. env command:
    This command prints a list of all environment variables and their values.

    env

    You'll see output like:

    SHELL=/bin/bash
    TERM=xterm
    USER=labex
    PATH=/usr/local/sbin:...
    # ... many more ...
    PWD=/home/labex/project
    HOME=/home/labex
    LOGNAME=labex

    Note: env specifically shows variables that are exported.

  2. printenv command:
    Similar to env, printenv also displays all environment variables. If you specify a variable name with printenv, it will only show the value of that specific variable.

    printenv

    To check a specific one:

    printenv HOME
  3. declare -x (Bash specific):
    If you're using Bash (which is the default on LabEx VMs), declare -x will show you all exported variables, including functions that are exported.

    declare -x
  4. set command (shows all shell variables, including exported ones):
    The set command without any arguments will display all variables (both shell variables and environment variables), along with shell functions and options. This can produce a very long output.

    set

    Because it includes everything, set is often more used for debugging or understanding a shell's entire state rather than just showing environment variables.

Which one to use?

  • For a clear list of just environment variables (exported variables), env or printenv are usually the best choices.
  • If you want to see everything defined in your current shell session, including non-exported shell variables, set is the command.

Go ahead and try one of them in your Web Terminal! For instance, type env and press Enter to see what's currently set in your LabEx environment.

Let me know if you want to explore any of these variables further!

0 Comments

no data
Be the first to share your comment!