Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

CHAPTER 8 csh : C SHEll The C shell program, csh, is a command language interpreter for XENIX system users. The C shell, like the standard XENIX shell sh, is an interface between you and XENIX commands and programs. It translates command lines typed at a terminal into corresponding system actions, gives you access to information such as your login name, home directory, and mailbox, and supports the construction of shell procedures for automating system tasks. This chapter explains how to use the C shell. It also explains the syntax and function of C shell commands and features and shows how to use these features to create shell procedures. The C shell is fully described in the entry csh in Appendix B, "Programming Commands." Invoking the C Shell You can invoke the C shell from another shell by typing the csh command csh at the standard shell's command line. You can also direct the system to invoke the C shell for you when you log in. If you have given the C shell as your login shell in your /etc/passwd file entry, the system automatically starts the C shell when you log in. After the system starts the C shell, the shell searches your home directory for the command files .cshrc and .login. If the shell finds the files, it executes the commands contained in them and then displays the C shell prompt, normally a percent sign (%}. The .cshrc file typically contains commands to be executed each time you start a C shell, and the .login file contains the commands to be executed each time you log into the system. The following is an example of a typical .login file: set ignoreeof set mail = (lusr/spool/mail/bill) set time = 15 set history = 10 mail This file contains several set commands. The set command is executed directly by the C shell; there is no corresponding XENIX program for this command. In the example, set is used to set the C-shell variable ignoreeof, which shields the C shell from logging out if CONTROL-D is pressed. Instead of CONTROL-D, the logout command is used to log out of the system. Setting the mail variable in the example causes the C shell to notify you if you receive any mail in the specified mailbox. 8-1

csh: C Shell XENIX Programming The C shell variable time is set to 15, causing the C shell to automatically print statistics lines for commands that execute for at least 15 seconds of CPU time. The variable history is set to 10, indicating that the C shell will remember the last 10 commands typed in its history list (described later). Finally, the XENIX mail program is invoked. When the C shell finishes processing the .login file, it begins reading commands from the terminal, prompting for each with % When you log out (by giving the logout command) the C shell prints logout and executes commands from the file .logout if it exists in your home directory. After that, the C shell term inates and XENIX logs you off the system. Using Shell Variab les The C shell maintains a set of variables. For example, in the above discussion, the variables history and time had the values 10 and 15. Each C shell variable has as its value an array of zero or more strings. C shell variables may be assigned values by the set command, which has several forms, the most useful of which is set name = value C shell variables can be used to store values to be used later in commands through a substitution mechanism. The C shell variables most commonly referenced are, however, those that the C shell itself refers to. By changing the values of these variables you can directly affect the behavior of the C shell. One of the most important variables is path, which contains a list of directory names. When you type a command name at your terminal, the C shell examines each named directory in turn until it finds an executable file with a name that corresponds to the name you typed. The set command with no arguments displays the values of all variables currently defined in the C shell. The following example shows typical default values: argv () home /usr/bill path (. /bin /usr/bin) prompt % shell /bi n/csh status 0 This output indicates that the variable path begins with the current directory indicated by dot (.), then /bin, and last /usr/bin. Your own local commands may be in the current directory. Normal XENIX commands reside in /bin and /usr/bin. 8-2

CHAPTER 8<br />

csh : C SHEll<br />

The C shell program, csh, is a command language interpreter for <strong>XENIX</strong> system users.<br />

The C shell, like the standard <strong>XENIX</strong> shell sh, is an interface between you and <strong>XENIX</strong><br />

commands and programs. It translates command lines typed at a terminal into<br />

corresponding system actions, gives you access to information such as your login name,<br />

home directory, and mailbox, and supports the construction of shell procedures for<br />

automating system tasks.<br />

This chapter explains how to use the C shell. It also explains the syntax and function of<br />

C shell commands and features and shows how to use these features to create shell<br />

procedures. The C shell is fully described in the entry csh in Appendix B, "Programming<br />

Commands."<br />

Invoking the C Shell<br />

You can invoke the C shell from another shell by typing the csh command<br />

csh<br />

at the standard shell's command line. You can also direct the system to invoke the C<br />

shell for you when you log in. If you have given the C shell as your login shell in your<br />

/e<strong>tc</strong>/passwd file entry, the system automatically starts the C shell when you log in.<br />

After the system starts the C shell, the shell searches your home directory for the<br />

command files .cshrc and .login. If the shell finds the files, it executes the commands<br />

contained in them and then displays the C shell prompt, normally a percent sign (%}.<br />

The .cshrc file typically contains commands to be executed each time you start a C<br />

shell, and the .login file contains the commands to be executed each time you log into<br />

the system. The following is an example of a typical .login file:<br />

set ignoreeof<br />

set mail = (lusr/spool/mail/bill)<br />

set time = 15<br />

set history = 10<br />

mail<br />

This file contains several set commands. The set command is executed directly by the<br />

C shell; there is no corresponding <strong>XENIX</strong> program for this command. In the example,<br />

set is used to set the C-shell variable ignoreeof, which shields the C shell from logging<br />

out if CONTROL-D is pressed. Instead of CONTROL-D, the logout command is used to<br />

log out of the system. Setting the mail variable in the example causes the C shell to<br />

notify you if you receive any mail in the specified mailbox.<br />

8-1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!