
CS 202
Programming With UNIX
Professor: Michael de la Maza
| Chapter 16: Interactive C Shell |
|
Topics:
|
Student Links:
Other Links: PowerPoint Presentation:
|
| References:
Unix and Shell Programming, by Forouzan & Gilberg E-Mail: Kris
|
|
C
Shell History: The C shell was developed by William Joy, the creator of the VI editor at the University of California, Berkeley. Like other UNIX shells, the C shell is a dual-purpose utility. It can be used interactively as an interpreter that reads, interprets and executes user commands. It can also be used to as a programming language to write shell scripts.
The pipe operator temporarily saves the output from one command in a buffer that is being used at the same time as the input to the next command. The tee command copies standard input to standard output and at the same time copies it to one or more files. Combining Commands can be done is four ways: Sequenced commands, grouped commands, chained commands, and conditional commands. The C shell does not support command-line editing. It is possible to edit commands using history commands. The C shell supports command substitution using back quotes. Command substitution is used to convert a command's output to a string that can be stored in another string or a variable . Job control is used to control how and where a job is executed. To create an aliases in the C shell means to create a customized command by assigning a name or acronym to a command.
There are two special files in UNIX that can be used in any shell. The trash file is a special file that is used for deleting data. The contents of the trash file are always empties immediately after receiving data. Physically there is only one trash file in a system. The trash file is owned by the super user. The other special type of file is called the Terminal file. The terminal file represents the terminal of each user. Because the terminal file represents a terminal, it can't not store data.
The C shell allows the user to store values in variables. A shell variable is a location in memory where values can be stored. The two classifications of variables are: user-defined and predefined. When the user defines a variable he or she should never choose a name as a predefined variable. The user must also keep in mind that the name of the variable must start with an alphabetic or underscore (_) character. Predefined variables are either shell variables or environmental variables. To store a value in a variable you use the set command. To access the value in a variable, the name of the variable must be preceded by a dollar sign. The Null variables are variables that have no value stores in them. You can store a null value in a variable by either assigning it a null string ("") or by assigning it nothing. Unsetting a variable means to clear a variable by assigning it a null value. A variable can also store a file name. And if you can believe it, a variable can actually stores the contents of a file. A command can also be stored in a variable.
The output statement in the C shell in the echo command. the echo command creates a file from its arguments. the commands arguments can be strings or variables. The echo command automatically adds a new line after the last argument. In the C shell, data can be read from a terminal or a file using its read construct. The C shell allows data to be read using its read construct. The C shell can also read word by word.
In the C shell, when a command is executed, it returns a value known as the exit status of the command. The exit status is stored in the status shell variable. Like all named variables, the exit status is accessible by using its name ($status). If a command completes successfully, it returns a zero value. The Zero value is interpreted as false.
The eval command is used when the C shell need to evaluate a command twice before executing it.
The environmental variables control the user environment. In the C shell, there are two types of environmental variables. Uppercase and lowercase. Usually the uppercase variables are set to be exportable and the lowercase variables are not. The CDPATH variable contains a list of path names separated by spaces. The HOME variable contains the path to your home directory. The default is your logon directory. The USER variable contains the logon name of the user as found in the password file. It can be used to display the user name. The mail variable contains the absolute pathname of the user's mailbox. As mail is received, the mail utility stores it in the file until the user is ready to read it. The PATH variable is used to search for a command directory. The primary prompt is set in the variable PROMPT. The C shell uses the primary prompt when it expects a command. The default for the C shell is the (%). There is also a secondary prompt that is used whenever a command is not completely coded on the first line. By default it is the (?). It has no variable and can't be changed. The login shell (SHELL) variable holds the path of your login shell. The TERM variable holds the description for the terminal you are using. TO display the value in a variable you can use the echo command for both exportable and nonexportable.
In the C shell there are what is called on-off variables. these variables can be used to control the way commands are executed. The no global (noglob) variable controls the expansion of wildcard tokens in a command. To customize the shell environment, you need to set, unset and display on-off variables. you can do this by using the set command if you want to unset an on-off variable you can use the unset command. To display which on-off variables are set you can use the set command without any arguments.
Each shell in UNIX uses one or more scripts to initialize the environment when a session is started. The C shell provides two sets of startup files: one system wide set created by the system administrator that establishes the basic shell configuration for all users and one personal set that tailors the shell for the individual user. There are a total of four startup files and two shutdown files. There are System Startup files and personal startup files. UNIX uses these startup files when ever a shell is started. When secession is terminated the C shell provides two shutdown files. One for the system and one for the user's personal use.
the C shell provides an extensive command history capability consisting of a combination of commands. environmental variables, and files. Every command except commands executed in a script are stored in a history file in out home directory. By default the filename is ~/.history. It can be renames provided that we store its pathname in the HISTFILE environmental variable. The command for listing, editing, and executing commands from the history file is history. When executed without any options the history command lists the last 16 commands.
In order to understand the behavior of a shell the user need to know how the C shell executes a command. Command execution is carried out in six steps: Command parsing, Variable Evaluation, Command Substitution, Redirection, wildcard expansion, and path determination.
|