W. Joy - An Introduction to the C shell (794270), страница 11
Текст из файла (страница 11)
Foreground jobs can bestopped by signals from the terminal caused by typing different control characters at thekeyboard (1.8, 2.6).gotoThe shell has a command goto used in shell scripts to transfer control to a given label(3.7).grepThe grep command searches through a list of argument files for a specified string. Thusgrep bill /etc/passwdwill print each line in the file /etc/passwd which contains the string ‘bill’. Actually,grep scans for regular expressions in the sense of the editors ‘ed (1)’ and ‘ex (1)’. Grepstands for ‘globally find regular expression and print’ (2.4).headThe head command prints the first few lines of one or more files.
If you have a bunch offiles containing text which you are wondering about it is sometimes useful to run headwith these files as arguments. This will usually show enough of what is in these files tolet you decide which you are interested in (1.5).Head is also used to describe the part of a pathname before and including the last ‘/’character. The tail of a pathname is the part after the last ‘/’. The ‘:h’ and ‘:t’ modifiersallow the head or tail of a pathname stored in a shell variable to be used (3.6).historyThe history mechanism of the shell allows previous commands to be repeated, possiblyafter modification to correct typing mistakes or to change the meaning of the command.The shell has a history list where these commands are kept, and a history variable whichcontrols how large this list is (2.3).home directoryEach user has a home directory , which is given in your entry in the password file,/etc/passwd .
This is the directory which you are placed in when you first login. The cdor chdir command with no arguments takes you back to this directory, whose name isrecorded in the shell variable home . You can also access the home directories of other----An Introduction to the C shellUSD:4-39users in forming filenames using a filename expansion notation and the character ‘˜’(1.6).ifA conditional command within the shell, the if command is used in shell commandscripts to make decisions about what course of action to take next (3.6).ignoreeofNormally, your shell will exit, printing ‘logout’ if you type a control-d at a prompt of ‘%’. This is the way you usually log off the system.
You can set the ignoreeof variable ifyou wish in your .login file and then use the command logout to logout. This is usefulif you sometimes accidentally type too many control-d characters, logging yourself off(2.2).inputMany commands on UNIX take information from the terminal or from files which theythen act on. This information is called input . Commands normally read for input fromtheir standard input which is, by default, the terminal.
This standard input can be redirected from a file using a shell metanotation with the character ‘<’. Many commandswill also read from a file specified as argument. Commands placed in pipelines will readfrom the output of the previous command in the pipeline . The leftmost command in apipeline reads from the terminal if you neither redirect its input nor give it a filename touse as standard input . Special mechanisms exist for supplying input to commands inshell scripts (1.5, 3.8).interruptAn interrupt is a signal to a program that is generated by typing ˆC. (On older versionsof UNIX the RUBOUT or DELETE key were used for this purpose.) It causes most programs to stop execution.
Certain programs, such as the shell and the editors, handle aninterrupt in special ways, usually by stopping what they are doing and prompting foranother command. While the shell is executing another command and waiting for it tofinish, the shell does not listen to interrupts. The shell often wakes up when you hitinterrupt because many commands die when they receive an interrupt (1.8, 3.9).jobOne or more commands typed on the same input line separated by ‘|’ or ‘;’ characters arerun together and are called a job .
Simple commands run by themselves without any ‘|’or ‘;’ characters are the simplest jobs. Jobs are classified as foreground , background , orsuspended (2.6).job controlThe builtin functions that control the execution of jobs are called job control commands.These are bg, fg, stop, kill (2.6).job numberWhen each job is started it is assigned a small number called a job number which isprinted next to the job in the output of the jobs command. This number, preceded by a‘%’ character, can be used as an argument to job control commands to indicate a specificjob (2.6).jobsThe jobs command prints a table showing jobs that are either running in the backgroundor are suspended (2.6).killA command which sends a signal to a job causing it to terminate (2.6)..loginThe file .login in your home directory is read by the shell each time you login to UNIXand the commands there are executed.
There are a number of commands which are usefully placed here, especially set commands to the shell itself (2.1).login shellThe shell that is started on your terminal when you login is called your login shell . It isdifferent from other shells which you may run (e.g. on shell scripts) in that it reads the.login file before reading commands from the terminal and it reads the .logout file afteryou logout (2.1).logoutThe logout command causes a login shell to exit.
Normally, a login shell will exit whenyou hit control-d generating an end-of-file, but if you have set ignoreeof in you .loginfile then this will not work and you must use logout to log off the UNIX system (2.8)..logoutWhen you log off of UNIX the shell will execute commands from the file .logout in yourhome directory after it prints ‘logout’.----USD:4-40An Introduction to the C shelllprThe command lpr is the line printer daemon. The standard input of lpr spooled andprinted on the UNIX line printer. You can also give lpr a list of filenames as arguments tobe printed. It is most common to use lpr as the last component of a pipeline (2.3).lsThe ls (list files) command is one of the most commonly used UNIX commands. With noargument filenames it prints the names of the files in the current directory.
It has a number of useful flag arguments, and can also be given the names of directories as arguments, in which case it lists the names of the files in these directories (1.2).mailThe mail program is used to send and receive messages from other UNIX users (1.1, 2.1),whether they are logged on or not.makeThe make command is used to maintain one or more related files and to organize functions to be performed on these files. In many ways make is easier to use, and more helpful than shell command scripts (3.2).makefileThe file containing commands for make is called makefile or Makefile (3.2).manualThe manual often referred to is the ‘UNIX manual’.
It contains 8 numbered sections witha description of each UNIX program (section 1), system call (section 2), subroutine (section 3), device (section 4), special data structure (section 5), game (section 6), miscellaneous item (section 7) and system administration program (section 8). There are alsosupplementary documents (tutorials and reference guides) for individual programs whichrequire explanation in more detail.
An online version of the manual is accessiblethrough the man command. Its documentation can be obtained online viaman manIf you can’t decide what manual page to look in, try the apropos (1) command. The supplementary documents are in subdirectories of /usr/doc.metacharacterMany characters which are neither letters nor digits have special meaning either to theshell or to UNIX.
These characters are called metacharacters . If it is necessary to placethese characters in arguments to commands without them having their special meaningthen they must be quoted . An example of a metacharacter is the character ‘>’ which isused to indicate placement of output into a file. For the purposes of the history mechanism, most unquoted metacharacters form separate words (1.4). The appendix to thisuser’s manual lists the metacharacters in groups by their function.mkdirThe mkdir command is used to create a new directory.modifierSubstitutions with the history mechanism, keyed by the character ‘!’ or of variablesusing the metacharacter ‘$’, are often subjected to modifications, indicated by placingthe character ‘:’ after the substitution and following this with the modifier itself.