Environment Variables


Earlier in this book, we touched on the concept of environmental variables in Unix. In Lesson 14, "Shell Scripting Fundamentals," variables used in the shell were discussed. To explain how environment variables are used, consider how your Unix system runs. Most of the programs are configured to run based on text files that help build the command into the environment for use. If you don't have a file, then most likely you will be setting a program up with an environmental variable. The environmental variable will essentially be where the program draws its essential configuration information from.

Environment variables are used by programs to pick up specific pieces of information that are needed when the program is run. For example, you might run across some programs that want an environment variable that contains the path to their help-file information and if not, they will not work when asked for help. This is a common issue revolving around the path usage. Remember, it is important to understand what the path is. This is another special shell variable called the path variable. It tells the shell where to look for programs that you want to execute. In this next example, we will look at the syntax of setting your environmental variables.

Environment variables aren't set using quite the same syntax as regular shell variables, so instead of using set <variablename>=<value>, use the following syntax:

 setenv <variablename> <value>. 

What Is an Environment Variable? Environmental variables are used by your Unix system to pass information to programs and customize their behavior.


When working with environmental variables, you should really work in a lab environment and test changes to the environment until you get used to making these changes. Absolute beginners on Unix should show caution when altering user environment settings and should always write down the changes they make; it is easy to be overwhelmed quickly.

The possibilities are endless, making settings changes easy.

What's Good for the Goose May Not Be Good for You When working with environmental variables, you need to consider the following. Remember that the settings you make in one shell do not affect other shells. If you need to access more than one configuration at a time, you can have the same environment variable set to different values in different shells you're running simultaneously.




    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net