0Pricing
Linux Command Line Mastery · درس

متغيرات البيئة والأسماء المستعارة

أدِر بيئة shell وخصّصها باستخدام متغيرات البيئة والأسماء المستعارة للأوامر.

متغيرات البيئة والأسماء المستعارة درس مجاني في Linux Command Line Mastery على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Linux Command Line Mastery، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Linux Command Line Mastery 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Your Shell's Environment

Welcome! In this lesson, we'll dive into how your Linux shell keeps track of important information. This 'environment' helps your commands run smoothly.

Think of it as your shell's personal workspace, full of settings and shortcuts.

Meet Environment Variables

Environment variables are dynamic named values that store information used by the shell and other programs. They let you customize how your system behaves.

  • They are like temporary storage for your shell.
  • They can hold paths, user settings, and more.
  • Other programs can read these variables to know how to act.

Checking Current Variables

You can see all active environment variables using the printenv command. To view a specific variable, use echo $VARIABLE_NAME.

The dollar sign $ before a variable name tells the shell to show its value.

printenv | head -n 3
echo $HOME

Important System Variables

Two very common and important environment variables are PATH and HOME:

  • PATH: A list of directories where the shell looks for executable commands. When you type ls, the shell checks these directories.
  • HOME: The absolute path to your home directory. This is where your personal files and settings are usually stored.

Setting Temporary Variables

You can create your own environment variables for the current shell session. Just assign a value to a name:

VARIABLE_NAME="value"

Note that there are no spaces around the = sign. These variables are temporary and disappear when you close the terminal.

MY_MESSAGE="Hello CoddyKit"
echo $MY_MESSAGE

# This variable only exists in this shell

Making Variables Global with 'export'

Variables set directly are only available in the current shell. To make them available to any sub-processes (like scripts or other commands you run from your current shell), you need to export them.

export GLOBAL_VAR="I am global"
bash -c 'echo $GLOBAL_VAR'

# Without export, 'bash -c' wouldn't see it.

Introducing Command Aliases

Command aliases are custom shortcuts for longer commands or sequences of commands. They save you typing and can even fix common typos.

  • They personalize your command-line experience.
  • You define a short name that expands to a longer command.
  • Great for frequently used, complex commands.

Creating Quick Shortcuts

To create an alias, use the alias command followed by name='command'. Like variables, these are temporary and last only for the current shell session.

A common example is aliasing ls -alF to ll for a detailed file listing.

alias ll='ls -alF'
ll

# Now 'll' runs 'ls -alF'

Listing and Removing Aliases

To see all aliases currently active in your shell, simply type alias without any arguments. If you want to remove an alias, use the unalias command.

alias
alias c='clear'
alias
unalias c
alias

Check Your Understanding

You've learned about environment variables and aliases. Let's test your knowledge!

Consider the following:

MY_VAR="Test"
export MY_VAR

Which statement is true after running these commands?

Lesson Summary

Great job! You've successfully explored environment variables and aliases.

  • Environment variables store key-value pairs for your shell and programs.
  • Use echo $VAR to see a variable's value and printenv to list them all.
  • export makes variables available to sub-processes.
  • Aliases are custom shortcuts for commands, created with alias name='command'.
  • Both are temporary by default, lasting only for the current shell session.

Next, you'll learn how to make these customizations permanent!

الأسئلة الشائعة

هل درس «متغيرات البيئة والأسماء المستعارة» مجاني؟

نعم — نص درس «متغيرات البيئة والأسماء المستعارة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Linux Command Line Mastery، انتقل إلى CoddyKit PRO. تتضمن دورة Linux Command Line Mastery 4 دروس في المجموع.

ماذا ستتعلم في «متغيرات البيئة والأسماء المستعارة»؟

أدِر بيئة shell وخصّصها باستخدام متغيرات البيئة والأسماء المستعارة للأوامر. تتمرن على Linux Command Line Mastery مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Linux Command Line Mastery؟

لا تُشترط خبرة سابقة. Linux Command Line Mastery على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «متغيرات البيئة والأسماء المستعارة»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Linux Command Line Mastery هذا؟

نعم. كل درس في Linux Command Line Mastery يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. أساسيات Git من سطر الأوامر
  2. متغيرات البيئة والأسماء المستعارة
  3. تهيئة Shell: `.bashrc` و`.zshrc` و`.profile`
  4. التفرّع والدمج باستخدام Git من سطر الأوامر
← العودة إلى Linux Command Line Mastery