0
0
Linux CLIscripting~5 mins

Environment variables in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an environment variable in Linux?
An environment variable is a named value stored by the operating system that programs can use to get information about the system or user settings. It acts like a note that programs can read to know how to behave.
Click to reveal answer
beginner
How do you display all environment variables in a Linux shell?
You can use the command printenv or env to list all environment variables currently set in your shell session.
Click to reveal answer
beginner
How do you set a new environment variable for the current shell session?
Use the command export NAME=value. For example, export MYVAR=hello sets an environment variable named MYVAR with the value 'hello' for the current session.
Click to reveal answer
intermediate
What happens to environment variables when you close the terminal?
Environment variables set in a terminal session are lost when you close that terminal unless saved in configuration files like ~/.bashrc or ~/.profile to load automatically on new sessions.
Click to reveal answer
beginner
How can you use an environment variable inside a shell script?
You can access an environment variable in a shell script by prefixing its name with a dollar sign, like $VARIABLE_NAME. For example, echo $HOME prints the home directory path.
Click to reveal answer
Which command shows all environment variables in Linux?
Amkdir
Bls
Ccd
Dprintenv
How do you set an environment variable named PATH to '/usr/bin' for the current session?
Aexport PATH=/usr/bin
Bset PATH=/usr/bin
CPATH=/usr/bin
Denv PATH=/usr/bin
What symbol do you use to access the value of an environment variable in a shell script?
A#
B$
C&
D*
Where should you save environment variable settings to make them permanent for your user?
A/tmp
B/etc/passwd
C~/.bashrc
D/var/log
If you set an environment variable in one terminal, will it be available in a new terminal window automatically?
ANo, unless saved in config files
BOnly if you reboot
CYes, always
DOnly if you use sudo
Explain what environment variables are and how they are used in Linux.
Think about how programs know about your system or preferences.
You got /4 concepts.
    Describe the steps to create a new environment variable that lasts across terminal sessions.
    Consider both temporary and permanent ways.
    You got /3 concepts.