Introduction to Linux in HPC/Environment variables

From HPC Wiki
Introduction to Linux in HPC/Environment variables /
Jump to navigation Jump to search

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

( Slides as pdf)

Quiz

How do you define an environment variable VARTEST and assign the value 42 to it?

VARTEST=42
export VARTEST=42
env VARTEST=42

What is the naming convention for environment variables?

Use uppercase letters
Use lowercase letters
There is no naming convention.

Which statement is correct for environment variables?

Environment variables are stored in a central database on a 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 as well as all programs or shell sessions that are started from this session.

What is the expected output of the following commands? VARTEST="bla"; export VARTEST

var="value"
var = "value"
var=="value"

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?

/usr/bin/program
/usr/local/bin/program
The shell will ask you which one to execute.

How do you add the directory /opt/bin/ to the PATH environment variable and make sure that it is searched last?

export PATH=/opt/bin/:$PATH
export PATH=$PATH:/opt/bin/
export PATH=/opt/bin/

Exercises in Terminal

1. a. Write a script that
   b. Prints an environment variable
   c. Saves the output of the date command to a variable
   d. Sleeps briefly
   e. Prints the new and old date and time
 2. What do different types of quotes (single ' vs. double ") do?
3. create an shell variable MYIDENTITY and export it as below: 
   $ export MYIDENTITY=whoami
   How will you list the shell variable MYIDENTITY?
   Execute the shell variable MYIDENTITY, what is the output? 



<< Shell Scripts

Overview

System Configuration Files >>