← Back to Bash Course | Chapter 2: Variables & Types | Lesson 5 of 13

Environment Variables क्या हैं

Environment variables school hallway में लगे signs जैसे हैं जो हर classroom पढ़ सकता है, जैसे कौन logged in है या आपका home folder कहां है। आपकी scripts इन्हें कभी भी देख सकती हैं।

In this page:

  1. Environment Variables
Syntax
bash
echo "$HOME"
echo "$USER"
echo "$PATH"

Environment Variables

$HOME, $USER, और $PATH जैसे environment variables system या shell द्वारा set होते हैं और हर script और program के लिए available हैं जो run होता है।

वे configuration और context carry करते हैं, जैसे current user की home directory। आप इन्हें किसी भी दूसरे variable की तरह पढ़ सकते हैं, $ के साथ।

Note: Currently set सभी environment variables देखने के लिए terminal में env या printenv run करें।

उदाहरण: Environment Variables

bash
#!/bin/bash
echo "Home directory: $HOME"
echo "Current user: $USER"
echo "Shell: $SHELL"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Script में एक variable set करना और इसे बाद में अपने terminal में दिखने की उम्मीद करना, क्योंकि एक script एक child process में run होती है।
  2. PATH=/new/dir set करना और old value खो देना; PATH="$PATH:/new/dir" लिखें।
  3. यह मान लेना कि variable names case-insensitive हैं, जब Home और HOME अलग हैं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.