Variabili d’ambiente e alias
Gestisca e personalizzi l’ambiente della shell usando variabili d’ambiente e alias dei comandi.
Variabili d’ambiente e alias è una lezione Linux Command Line Mastery gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Linux Command Line Mastery, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Linux Command Line Mastery include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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!
Domande Frequenti
La lezione «Variabili d’ambiente e alias» è gratuita?
Sì — il testo completo di «Variabili d’ambiente e alias» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Linux Command Line Mastery, passa a CoddyKit PRO. Il corso Linux Command Line Mastery include 4 lezioni in totale.
Cosa imparerò in «Variabili d’ambiente e alias»?
Gestisca e personalizzi l’ambiente della shell usando variabili d’ambiente e alias dei comandi. Eserciti Linux Command Line Mastery con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Linux Command Line Mastery?
Non è richiesta alcuna esperienza precedente. Linux Command Line Mastery su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Variabili d’ambiente e alias»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Linux Command Line Mastery?
Sì. Ogni lezione Linux Command Line Mastery include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Basi di Git dalla riga di comando
- Variabili d’ambiente e alias
- Configurazione della shell: `.bashrc`, `.zshrc`, `.profile`
- Branching e merging con Git dalla riga di comando