Chapter 3. Environment Variables

   

Chapter 3. Environment Variables

Chapter Syllabus

3.1 Environment and Shell Variables

3.2 Setting and Displaying Variables

3.3 Predefined Environment Variables

3.4 Exporting Shell Variables

3.5 Setting the Command Prompt

3.6 The PATH Variable

As soon as a user logs into HP-UX, the shell is invoked and waits for commands from the user . To execute these commands, the shell needs to know some information about the environment being used. For example, to correctly display a file, the shell needs to know which type of terminal is attached to the system. Similarly, when a user issues an extrinsic command, the shell needs to know in which directories it should look for the command. In UNIX terminology, we call this type of information the shell environment.

The shell stores environment information in environment variables. Usually, many types of variables are set in the system startup file ( /etc/profile ) managed by the system administrator. The users can also set environment variables through the use of a user startup file kept in the home directory ( .profile ).

Any program that needs environment variables checks the existence and value of these variables at the startup time. For example, the editor program vi needs your terminal information to correctly display and scroll text. When you start the vi editor, it will check the TERM variable. If it understands the terminal type set by the TERM variable, it will start in full screen mode; otherwise , it will start in line editing mode, where you can edit or display only one line of text at a time. Similarly, the more command needs the TERM variable to display a particular number of text lines, depending on the type of terminal being used.

You can modify and change environment variables set by the system administrator. The system administrator usually sets the PATH variable that shows the search path for the executable commands. But as you start using the UNIX system, you also create your own programs and scripts, and you want the shell to look into the directories containing your own programs as well. For this purpose, you can add your own directory names in the PATH variable.

In this chapter, you will see the difference between environment and shell variables and how to set and display variables. There are many predefined environment variables, and the most important of these will be discussed. Then you will learn how to increase the visibility of a shell variable by exporting it. The default HP-UX command prompt shows little information, and you will see how to add some useful information to it using variables. Since PATH is an important variable, you will learn more about it at the end of the chapter.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

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