0Pricing
Linux Command Line Mastery · Урок

Переменные окружения и псевдонимы

Управляйте окружением оболочки и настраивайте его с помощью переменных окружения и псевдонимов команд.

«Переменные окружения и псевдонимы» — бесплатный урок 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 уроков всего.

Чему я научусь в уроке «Переменные окружения и псевдонимы»?

Управляйте окружением оболочки и настраивайте его с помощью переменных окружения и псевдонимов команд. Ты практикуешь 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 включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Основы Git из командной строки
  2. Переменные окружения и псевдонимы
  3. Настройка оболочки: `.bashrc`, `.zshrc`, `.profile`
  4. Ветвление и слияние с Git из командной строки
← Назад к Linux Command Line Mastery