Variabel Lingkungan dan Alias
Kelola dan sesuaikan lingkungan shell menggunakan variabel lingkungan dan alias perintah.
Variabel Lingkungan dan Alias adalah pelajaran Linux Command Line Mastery gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Linux Command Line Mastery, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Linux Command Line Mastery mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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 $HOMEImportant 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 typels, 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 shellMaking 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
aliasCheck 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 $VARto see a variable's value andprintenvto list them all. exportmakes 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!
Belajar Linux Command Line Mastery dengan tutor AI — gratis
Tulis dan jalankan kode asli di browser kamu, dapatkan bantuan instan dari tutor AI 24/7, dan lanjutkan di mana kamu tinggalkan di web atau aplikasi.
- Kursus
- 12
- Pelajaran
- 48
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Variabel Lingkungan dan Alias” gratis?
Ya — teks lengkap “Variabel Lingkungan dan Alias” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Linux Command Line Mastery, upgrade ke CoddyKit PRO. Kursus Linux Command Line Mastery mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Variabel Lingkungan dan Alias”?
Kelola dan sesuaikan lingkungan shell menggunakan variabel lingkungan dan alias perintah. Kamu berlatih Linux Command Line Mastery dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Linux Command Line Mastery?
Tidak diperlukan pengalaman sebelumnya. Linux Command Line Mastery di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.
Berapa lama pelajaran “Variabel Lingkungan dan Alias” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Linux Command Line Mastery ini?
Ya. Setiap pelajaran Linux Command Line Mastery menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Dasar-Dasar Git dari Baris Perintah
- Variabel Lingkungan dan Alias
- Konfigurasi Shell: `.bashrc`, `.zshrc`, `.profile`
- Membuat Cabang dan Menggabungkannya dengan Git dari Baris Perintah