Command Line Variables

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we’re going to practice setting and using variables in Bash. Variables are an important part of the command line, as well as writing shell scripts. Becoming familiar and comfortable with environment variables is an important step in using Linux.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Examine the Current `$PATH` Variable
  1. List the current environment variables, and locate the $PATH variable.
  2. Examine the $PATH variable.
    echo $PATH
Append the Path to the `scripts` Directory to the $PATH Variable
  1. Since the path to our scripts directory is missing, we need to append it to the $PATH variable. We can do so with the following command:
  2. We should now be able to run the script without specifying the path to it.
Make the New `$PATH` Persist
  1. If we log out, we’ll lose our ability to run the script without specifiying the path. So we need to make our change permanent. We can do so on this Ubuntu 16.04 system by modifying the ~/.profile file.
    echo 'PATH="$PATH:$HOME/scripts"' >> ~/.profile

Additional Resources

You've been asked to resolve a problem with an executable script located in /home/cloud_user/scripts/ The script is not running unless the path is provided. You will need to modify the $PATH environment variable to enable this script to run without providing its location.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?