O'Reilly logo

Linux® Command Line and Shell Scripting Bible by Richard Blum

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Using Linux Environment Variables

IN THIS CHAPTER

  • Using environment variables

  • Setting your own environment

  • variables

  • Advanced variable techniques

  • Using aliases

Linux environment variables help define your Linux shell experience. However, they can be a confusing topic for new Linux users. Many programs and scripts use environment variables to obtain system information and store temporary data and configuration information. There are lots of places where environment variables are set on the Linux system, and it's important to know where these places are. This chapter walks you through the world of Linux environment variables, showing where they are, how to use them, and even how to create your own. The chapter finishes off with a related topic, defining and using aliases in your shell session.

What Are Environment Variables?

The bash shell uses a feature called environment variables to store information about the shell session and the working environment (thus the name environment variables). This feature also allows you to store data in memory that can be easily accessed by any program or script running from the shell. This is a handy way to store persistent data that identifies features of the user account, system, shell, or anything else you need to store.

There are two types of environment variables in the bash shell:

  • Global variables

  • Local variables

This section describes each type of environment variables, and shows how to see and use them.

Note

Even though the bash shell uses ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required