Difference between revisions of "Introduction to Linux in HPC/Environment variables"
Introduction to Linux in HPC/Environment variables
Jump to navigation
Jump to search
m |
m |
||
Line 54: | Line 54: | ||
- An environment variable that was defined is valid and accessible in every shell session on this computer. | - An environment variable that was defined is valid and accessible in every shell session on this computer. | ||
|| | || | ||
− | + An environment variable is valid in the shell session in which it was defined | + | + An environment variable is valid in the shell session in which it was defined and is inherited to all programs or shell sessions that are started from this session. |
|| Explanation: Environment variables are inherited from parent processes to their child processes. | || Explanation: Environment variables are inherited from parent processes to their child processes. | ||
</quiz> | </quiz> | ||
Line 107: | Line 107: | ||
− | 1. a. | + | 1. Run the following step in a shell session |
− | b. | + | a. Define an environment variable named <code>TEST_VAR1="test1"</code>. |
− | c. | + | b. Define a shell variable names <code>TEST_VAR2="test2"</code>. |
− | + | b. Make sure that <code>TEST_VAR1</code> it is in the list of environment variables. | |
− | + | c. Start a new shell session within the current session. | |
+ | d. Output the content of the two variables <code>TEST_VAR1</code> and <code>TEST_VAR2<code>. | ||
+ | e. Change content of the environment variable to <code>TEST_VAR1="test_new"</code>. | ||
+ | f. Exit the shell session and output the content of <code>TEST_VAR1</code>. | ||
{| role="presentation" class="wikitable mw-collapsible mw-collapsed" | {| role="presentation" class="wikitable mw-collapsible mw-collapsed" | ||
| <strong>Answer:</strong> | | <strong>Answer:</strong> | ||
|- | |- | ||
| | | | ||
− | + | The commands to enter are: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | export TEST_VAR1="test1" | |
− | + | TEST_VAR2="test2" | |
− | + | env | grep TEST_VAR1 | |
− | + | bash | |
− | + | echo $TEST_VAR1 | |
− | + | echo $TEST_VAR2 | |
− | + | export TEST_VAR1="test_new" | |
− | echo | + | exit |
+ | echo $TEST_VAR1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|} | |} | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{Tutorial Navigation | {{Tutorial Navigation |
Revision as of 15:04, 22 November 2020
Tutorial | |
---|---|
Title: | Introduction to Linux in HPC |
Provider: | HPC.NRW
|
Contact: | tutorials@hpc.nrw |
Type: | Multi-part video |
Topic Area: | HPC Platforms |
License: | CC-BY-SA |
Syllabus
| |
1. Background and History | |
2. The Command Line | |
3. Linux Directory Structure | |
4. Files | |
5. Text display and search | |
6. Users and permissions | |
7. Processes | |
8. The vim text editor | |
9. Shell scripting | |
10. Environment variables | |
11. System configuration | |
12. SSH Connections | |
13. SSH: Graphics and File Transfer | |
14. Various tips |
This part of the Linux tutorials introduces environment variables and explains the difference to shell variables that have been introduced in Shell Scripting. A few important use cases for environment variables are discussed such as the OATH variable that determines where the shell searches for executable programs. Environment variables are also used by the so-called environment modules that are the main way to access software installed on an HPC cluster. Environment modules are explained shortly in this tutorial.
Video
Quiz
How do you define an environment variable VARTEST and assign the value 42 to it?
What is the naming convention for environment variables?
Which statement is correct for environment variables?
What is the expected output of the following commands?
VARTEST="bla"; export VARTEST; VARTEST="blub"; env
Assume that the environment variable PATH
has the following content PATH="/usr/bin:/usr/local/bin"
. There is a program in each directory, i.e., /usr/bin/program
and /usr/local/bin/program
. Which will be executed if you run program
in the shell?
How do you add the directory /opt/bin/
to the PATH
environment variable and make sure that it is searched last?
Exercises in Terminal
1. Run the following step in a shell session
a. Define an environment variable named TEST_VAR1="test1"
.
b. Define a shell variable names TEST_VAR2="test2"
.
b. Make sure that TEST_VAR1
it is in the list of environment variables.
c. Start a new shell session within the current session.
d. Output the content of the two variables TEST_VAR1
and TEST_VAR2.
e. Change content of the environment variable to TEST_VAR1="test_new"
.
f. Exit the shell session and output the content of TEST_VAR1
.
Answer:
The commands to enter are:
export TEST_VAR1="test1"
TEST_VAR2="test2"
env | grep TEST_VAR1
bash
echo $TEST_VAR1
echo $TEST_VAR2
export TEST_VAR1="test_new"
exit
echo $TEST_VAR1