الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

printenv

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

المستوى
لينكس اليومي
المجموعة
الطرفية والمساعدة
يحتاج root
لا
الحزمة
coreutils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الخيارات 4

الأكثر استخدامًا

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.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع 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.

انتبه

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

نصائح للحفظ

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man printenv