Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

printenv

Print the value of environment variables (all, or the ones you name).

Niveau
Dagelijks Linux
Groep
Shell en hulp
Root nodig
Nee
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

printenv without arguments prints every environment variable (like env). With names, it prints only the values, one per line, and returns an error code when a variable does not exist. That makes it handy in scripts and checks.

It only shows exported variables. A shell variable that was not exported is not printed.

Zo schrijf je het

printenv [OPTION]... [VARIABLE]...

Opties 4

Meest gebruikt

VARIABLE
Print only the value of this variable. Several names are allowed.
-0, --null
End each output line with a NUL byte instead of a new line.
--help
Show help.
--version
Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Print one value

    printenv HOME
    /home/student

    Only the value, no name. Easy to use in scripts.

  2. 2Print several values

    printenv USER SHELL LANG
    student
    /bin/bash
    en_US.UTF-8

    One line per variable, in the order you asked.

  3. 3Print all environment variables

    printenv | sort

    Same list as env, sorted by name.

  4. 4Check if a variable exists

    printenv KUBECONFIG >/dev/null || echo "KUBECONFIG is not set"

    The exit code is 1 when the variable is missing.

  5. 5Make a script stop when a needed variable is missing

    for v in DB_HOST DB_USER; do printenv "$v" >/dev/null || { echo "missing $v"; exit 1; }; done

    Fail early with a clear message, before the script touches anything.

  6. 6Check the proxy settings

    printenv | grep -i _proxy

    Wrong proxy variables are a common reason why downloads fail on servers.

  7. 7See the PATH one folder per line

    printenv PATH | tr ':' '\n'

    Easy to see a wrong or missing folder.

  8. 8Compare a variable as your user and with sudo

    printenv PATH; sudo printenv PATH

    sudo uses its own safe PATH (from secure_path in sudoers).

  9. 9Check what a systemd service gets (test a unit)

    systemd-run --user --wait --pipe printenv | head

    Runs printenv the way a service would run, so you see its environment.

  10. 10Print a variable that a CI job sets

    printenv CI_COMMIT_SHA

    CI systems pass build data in environment variables; print them to debug a pipeline step.

  11. 11Print values with NUL separators

    printenv -0 USER HOME | xargs -0 -n1 echo

    Safe for values that contain spaces or new lines.

Let op

  • Do not write $ before the name: printenv HOME, not printenv $HOME.
  • Not exported = not printed. Use echo "$NAME" or set for shell variables.

Tips om te onthouden

  • printenv NAME = value only. env = all. echo $NAME = also non-exported variables.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man printenv