環境変数とエイリアス
環境変数とコマンドエイリアスを使って、シェル環境を管理・カスタマイズします。
「環境変数とエイリアス」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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 $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!
よくある質問
「環境変数とエイリアス」レッスンは無料ですか?
はい。「環境変数とエイリアス」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。
「環境変数とエイリアス」で何を学びますか?
環境変数とコマンドエイリアスを使って、シェル環境を管理・カスタマイズします。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Linux Command Line Masteryを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「環境変数とエイリアス」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このLinux Command Line Masteryレッスンでコードを書いて実行できますか?
はい。すべてのLinux Command Line Masteryレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。