Explore essential concepts and practical commands for managing environment variables in Linux. This quiz covers variable scopes, syntax, modification techniques, and common pitfalls to help sharpen your understanding of Linux environment variables.
Which command will correctly display the value of the PATH environment variable in a Linux terminal?
Explanation: The correct command is 'echo $PATH', which uses the echo utility along with the dollar sign to expand and print the value of the PATH variable. 'echo PATH' would print the literal text 'PATH' rather than its value. 'print PATH' is not a standard command in most Linux shells. 'list $PATH' is incorrect because 'list' is not a command for displaying variables. Only 'echo $PATH' properly shows the variable's value.
What is the effect of running the command 'export MYVAR=hello' in a Bash shell session?
Explanation: Using 'export MYVAR=hello' makes MYVAR available to the current shell and all child processes spawned after this command. Defining MYVAR without 'export' would restrict it to the current process. The command does not delete or remove variables, so option three is incorrect. Option four is incorrect because 'export' ensures inheritance by child processes, not restriction.
Given the command 'VAR=test ls', what will be the value of VAR after the command completes in the same shell session?
Explanation: When a variable is set directly before a command like 'VAR=test ls', the variable's value is only available for that specific command and its execution environment. The variable does not persist after the command completes, so it remains unset or unchanged in the shell. Permanently setting a variable requires a different syntax, and deleting it or prompting for a new value does not happen with this command structure.
Which command will correctly remove the environment variable TEMP_VAR from the current shell session?
Explanation: The 'unset TEMP_VAR' command properly removes the variable TEMP_VAR from the environment of the current shell. 'delete' is not a valid shell command for variables. 'remove $TEMP_VAR' is not recognized and the use of the dollar sign is incorrect when unsetting. 'unset $TEMP_VAR' is incorrect as the dollar sign refers to the variable's value, not its name.
To make a new environment variable EDITOR persist for every future terminal session, which file should you add the 'export EDITOR=vim' line to?
Explanation: The ~/.bashrc file is designed for command and environment configurations that should be loaded in each new shell session for a specific user. /var/log/syslog is a log file and unrelated to environment variable setup. ~/.local/share is a data directory, not a shell configuration script. /usr/bin/ls is an executable and modifying it is neither intended nor safe for setting variables.