Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
Shells: User's Guide: HP 9000 Computers > Chapter 13 Shell Variables

Built-In Shell Variables

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

C Shell maintains a set of variables that can be assigned values by the set command. Shell variables are useful for storing values for later use in commands. The most commonly referenced shell variables are, however, those which the shell itself refers to. By changing the values of these variables, you can directly affect the shell behavior. The following variables are supported by C Shell on HP-UX.

argv

This variable contains the command line arguments from the calling shell.

autologout

This variable is used to automatically log you off the system if you do not use the system for a specified amount of time. For example,

set autologout = 60

will automatically log you off the system if you do not use the system for an hour (60 minutes).

To disable autologout, set it to zero (0) time. For example:

set autologout = 0

or

unset autologout

cwd

The cwd variable contains the path name to your current working directory. This variable is automatically changed with each cd (Change Directory) command. At logon, the default for this variable is the directory in the system variable HOME.

home

The home variable contains the path name to your home directory. The default value for this variable is specified in the system file /etc/passwd. (See passwd(5).)

Boolean ignoreeof

The boolean variable ignoreeof determines whether CTRL-D is allowed to log you off the system. If set,

set ignoreeof

logout must be used to terminate a session. If ignoreeof is unset,

unset ignoreeof

you can also use CTRL-D to log off. The default is set.

cdpath

Use this variable to specify alternate directories to be searched by the system when locating subdirectory arguments used with pushd, cd, and chdir commands.

Boolean noclobber

Suppose you use the following command sequence to send keyboard input to a file called newfile.

cat > newfile

If newfile exists before this command sequence is executed, the old copy of newfile will be overwritten and thus destroyed. To prevent accidental overwriting of a file containing valuable information, set the boolean noclobber variable so that C Shell cannot overwrite files by including the command line:

set noclobber

in your .login file. To demonstrate its effectiveness, type the following C Shell commands:

% cat > newfile
This is a test message.
EOT
%set noclobber
cat > newfile
newfile: File Exists.
%

When you try to cat to an existing file with noclobber set, the system tells you the File Exists and aborts the command. To override the noclobber, use the exclamation point metacharacter. For example:

%cat > newfile
newfile: File Exists.
%cat >! newfile
This is an override test.
EOT
%

Boolean notify

If the notify variable is set, you are immediately notified when a background process finishes. If unset, notification messages related to background process completion occur with the next presentation of the C Shell prompt. Use the set command to set notify.

path

The path variable is one of the most important variables in C Shell operation. This variable contains a sequence of directory names C Shell searches for commands. For example:

set path=(/bin/posix /bin /usr/bin /usr/local/bin /usr/bin /etc .)

or

setenv PATH /bin/posix:/bin:/usr/bin:/usr/local/bin:/etc:.

PATH is a system variable, and path is a C Shell variable that serves the same purpose. The first is global, while the second is local to the running shell.

When C Shell is first executed, a hash table of command locations is created. This table is created by looking through the directories specified in PATH (except for the current working directory) in the order specified by PATH. Suppose you were to write one or more new commands and store them in one of the directories in your path other than your current working directory. The system has no way of knowing they are there until you notify it of their presence by using the rehash command. The hash table never gets built from commands in ., your current working directory, so new commands put into . don't affect the hash table. But, if your path contained $HOME/tools/bin and you put a new command in there, then rehash would add it to hash table. The hash table also gets rebuilt whenever your PATH is changed.

prompt

This variable is used to customize your C Shell prompt. For example,

% set prompt = "[\!] % "
[22] % _

sets the prompt to indicate the command (event) number of the current command. This is very useful when using the History mechanism.

shell

Some HP-UX commands, such as mailx and vi, spawn a new shell when they begin execution, while others may spawn one or more new shells during normal operation. If the program or command is written so that it recognizes the shell variable, you can set the variable to define the type of shell to be spawned by the program. For example:

set shell = /bin/csh

selects C Shell, while

set shell = /bin/posix/sh

selects POSIX Shell.

This technique is valid only if the command or program recognizes that uses the variable when spawning new shells. Be careful when using the shell variable. The result may or may not be what you intended.

status

This variable returns 0 if the most recently executed command was completed without error. A nonzero value means an error was detected.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-1991 Hewlett-Packard Development Company, L.P.