Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
100%
(3)
100% found this document useful (3 votes)
913 views
The Unix Programming Environment
Uploaded by
Leo Wong
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save The Unix Programming Environment For Later
Download
Save
Save The Unix Programming Environment For Later
100%
100% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
100%
(3)
100% found this document useful (3 votes)
913 views
The Unix Programming Environment
Uploaded by
Leo Wong
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save The Unix Programming Environment For Later
Carousel Previous
Carousel Next
Save
Save The Unix Programming Environment For Later
100%
100% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 369
Search
Fullscreen
2 dl The UNIX Programming Environment Brian W. Kernighan Rob Pike Bell Laboratories Murray Hill, New Jersey PRENTICE-HALL, INC. Englewood Cliffs, New Jersey 07632 * UNIX is a Trademark of Bell LaboratoriesLibrary of Congress Catalog Card Number 8 3 -6 285 1 Prentice-Hall Software Series Brian W. Kernighan, Advisor Editorial/production supervision: Ros Herion Cover design: Photo Plus Art, Celine Brandes Manufacturing buyer: Gordon Osbourne Copyright © 1984 by Bell Telephone Laboratories, Incorporated. Alll rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopy- ing, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Published simultaneously in Canada. This book was typeset in Times Roman and Courier by the authors, using a Mer- genthaler Linotron 202 phototypesetter driven by a VAX-11/750 running the 8th Edition of the UNIX operating system. UNIX is a trademark of Bell Laboratories. DEC, PDP and VAX are trademarks of Digital Equipment Corporation. 20:19 18 17 16 1S 14 ISBN O-13-937b99-2 ISBN O-13-937?b81-X {PBK} PRENTICE-HALL INTERNATIONAL, INC., London PRENTICE-HALL OF AUSTRALIA PTY. LIMITED, Sydney EDITORA PRENTICE-HALL DO BRASIL, LTDA., Rio de Janeiro PRENTICE-HALL CANADA INC., Toronto PRENTICE-HALL OF INDIA PRIVATE LIMITED, New Delhi PRENTICE-HALL OF JAPAN, INC., Tokyo PRENTICE-HALL OF SOUTHEAST ASIA PTE. LTD., Singapore WHITEHALL BOOKS LIMITED, Wellington, New Zealand3. 4. Preface UNIX for Beginners 1.1 Getting started 1.2. Day-to-day use: files and common commands 1.3 More about files: directories 1.4 The shell 1.5 The rest of the UNIX system The File System 2.1. The basics of files 2.2 What’s in a file? 2.3. Directories and filenames 2.4. Permissions 2.5. Inodes 2.6. The directory hierarchy 2.7 Devices Using the Shell 3.1 Command line structure 3.2 Metacharacters 3.3 Creating new commands 3.4 Command arguments and parameters 3.5 Program output as arguments 3.6 Shell variables 3.7 More on I/O redirection 3.8 Looping in shell programs 3.9 bundle: putting it all together 3.10 Why a programmable shell? Filters 4.1 The grep family 4.2. Other filters iii CONTENTS 101 102 106< CONTENTS. 4.3 The stream editor sea 108 4.4 The awk pattern scanning and processing language 114 4.5 Good files and good filters 130 5. Shell Programming 133 5.1 Customizing the cal command 133 5.2 Which command is which? 138 5.3 while and until loops: watching for things 144 5.4 Traps: catching interrupts 150 5.5 Replacing a file: overwrite 152 5.6 zap: killing processes by name 156 5.7 The pick command: blanks vs. arguments 159 5.8 The news command: community service messages 162 5.9 get and put: tracking file changes 165 5.10 A look back 169 6. Programming with Standard /O 171 6.1 Standard input and output: vis 172 6.2 Program arguments: vis version 2 174 6.3 File access: vis version 3 176 6.4 A screen-at-a-time printer: p 180 6.5 Anexample: pick 186 6.6 On bugs and debugging 187 6.7 Anexample: zap 190 6.8 An interactive file comparison program: idiff 192 6.9 Accessing the environment 199 7 UNIX System Calls 201 7.1 Low-level /O 201 7.2 File system: directories 208 7.3 File system: inodes 214 7.4 Processes 220 7.5 Signals and interrupts 225 8. Program Development 233 8.1 Stage 1: A four-function calculator 234 8.2 Stage 2: Variables and error recovery 242 8.3 Stage 3: Arbitrary variable names; built-in functions 245 8.4 Stage 4: Compilation into a machine 258 8.5 Stage 5: Control flow and relational operators 266 8.6 Stage 6: Functions and procedures; input/output 273 8.7 Performance evaluation 284 8.8 A look back 28610. Document Preparation 9.1 The ms macro package 9.2 The troff level 9.3 The tbl and eqn preprocessors 9.4 The manual page 9.5 Other document preparation tools Epilog Appendix 1: Editor Summary Appendix 2: hoc Manual Appendix 3: hoc Listing Index CONIENLS. v 289 290 297 301 308 313 318 319 329 335 349= 43 44 4.5 CONTENTS The stream editor sed The awk pattern scanning and processing language Good files and good filters 5. Shell Programming 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 Customizing the cal command Which command is which? while and until loops: watching for things Traps: catching interrupts Replacing a file: overwrite zap: killing processes by name The pick command: blanks vs. arguments The news command: community service messages get and put: tracking file changes 5.10 A look back 6. Programming with Standard 1/0 Standard input and output: vis Program arguments: vis version 2 File access: vis version 3 A screen-at-a-time printer: p An example: pick On bugs and debugging An example: zap An interactive file comparison program: idiff Accessing the environment 7. UNIX System Calls el 7.2 73 74 75 Low-level 1/0 File system: directories File system: inodes Processes Signals and interrupts 8. Program Development 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 Stage 1: A four-function calculator Stage 2: Variables and error recovery Stage 3: Arbitrary variable names; built-in functions Stage 4: Compilation into a machine Stage 5: Control flow and relational operators Stage 6: Functions and procedures; input/output Performance evaluation A look back 108 130 133 133 13810. Document Preparation 9.1 The ms macro package 9.2 The trofé level 9.3 The tbi and eqn preprocessors 9.4 The manual page 9.5. Other document preparation tools Epilog Appendix 1: Editor Summary Appendix 2: hoc Manual Appendix 3: hoc Listing Index CONTENTS. v 289 290 297 301 308 313 315 319 329 335 349PREFACE “The number of UNIX installations has grown to 10, with more expected.” (The UNIx Programmer's Manual, 2nd Edition, June, 1972.) The UNIXt operating system started on a cast-off DEC PDP-7 at Bell Labora- tories in 1969. Ken Thompson, with ideas and support from Rudd Canaday, Doug Mcliroy, Joe Ossanna, and Dennis Ritchie, wrote a small general- purpose time-sharing system comfortable enough to attract enthusiastic users and eventually enough credibility for the purchase of a larger machine — a PDP-11/20. One of the early users was Ritchie, who helped move the system to the PDP-11 in 1970. Ritchie also designed and wrote a compiler for the C programming language. In 1973, Ritchie and Thompson rewrote the UNIX ker- nel in C, breaking from the tradition that system software is written in assem- bly language. With that rewrite, the system became essentially what it is today. Around 1974 it was licensed to universities “for educational purposes” and a few years later became available for commercial use. During this time, UNIX systems prospered at Bell Labs, finding their way into laboratories, software development projects, word processing centers, and operations support systems in telephone companies. Since then, it has spread world-wide, with tens of thousands of systems installed, from microcomputers to the largest main- frames. What makes the UNIX system so successful? We can discern several rea- sons. First, because it is written in C, it is portable — UNIX systems run on a range of computers from microprocessors to the largest mainframes; this is a strong commercial advantage. Second, the source code is available and written in a high-level language, which makes the system easy to adapt to particular requirements. Finally, and most important, it is a good operating system, + UNIX is a trademark of Bell Laboratories. “UNIX” is not an acronym, but a weak pun on MUL- TICS, the operating system that Thompson and Ritchie worked on before UNIX. viiPREFACE especially for programmers. The UNIX programming environment is unusually rich and productive. Even though the UNIX system introduces a number of innovative programs and techniques, no single program or idea makes it work well. Instead, what makes it effective is an approach to programming, a philosophy of using the computer. Although that philosophy can’t be written down in a single sen- tence, at its heart is the idea that the power of a system comes more from the relationships among programs than from the programs themselves. Many UNIX programs do quite trivial tasks in isolation, but, combined with other pro- grams, become general and useful tools. Our goal in this book is to communicate the UNIX programming philosophy. Because the philosophy is based on the relationships between programs, we must devote most of the space to discussions about the individual tools, but throughout run the themes of combining programs and of using programs to build programs. To use the UNIX system and its components well, you must understand not only how to use the programs, but also how they fit into the environment. As the UNIX system has spread, the fraction of its users who are skilled in its application has decreased. Time and again, we have seen experienced users, ourselves included, find only clumsy solutions to a problem, or write programs to do jobs that existing tools handle easily. Of course, the elegant solutions are not easy to see without some experience and understanding. We hope that by reading this book you will develop the understanding to make your use of the system — whether you are a new or seasoned user — effective and enjoyable. We want you to use the UNIX system well. We are aiming at individual programmers, in the hope that, by making their work more productive, we can in turn make the work of groups more productive. Although our main target is programmers, the first four or five chapters do not require programming experience to be understood, so they should be helpful to other users as well. Wherever possible we have tried to make our points with real examples rather than artificial ones. Although some programs began as examples for the book, they have since become part of our own set of everyday programs. All examples have been tested directly from the text, which is in machine-readable form. The book is organized as follows. Chapter | is an introduction to the most basic use of the system. It covers logging in, mail, the file system, commonly- used commands, and the rudiments of the command interpreter. Experienced users can skip this chapter. Chapter 2 is a discussion of the UNIX file system. The file system is central to the operation and use of the system, so you must understand it to use the system well. This chapter describes files and directories, permissions and file modes, and inodes. It concludes with a tour of the file system hierarchy and an explanation of device files.
You might also like
Hourglass Workout Program by Luisagiuliet 2
PDF
76% (21)
Hourglass Workout Program by Luisagiuliet 2
51 pages
12 Week Program: Summer Body Starts Now
PDF
87% (46)
12 Week Program: Summer Body Starts Now
70 pages
Read People Like A Book by Patrick King-Edited
PDF
58% (81)
Read People Like A Book by Patrick King-Edited
12 pages
Livingood, Blake - Livingood Daily Your 21-Day Guide To Experience Real Health
PDF
77% (13)
Livingood, Blake - Livingood Daily Your 21-Day Guide To Experience Real Health
260 pages
Cheat Code To The Universe
PDF
94% (79)
Cheat Code To The Universe
34 pages
Facial Gains Guide (001 081)
PDF
91% (45)
Facial Gains Guide (001 081)
81 pages
Curse of Strahd
PDF
95% (467)
Curse of Strahd
258 pages
The Psychiatric Interview - Daniel Carlat
PDF
91% (34)
The Psychiatric Interview - Daniel Carlat
473 pages
The Borax Conspiracy
PDF
91% (57)
The Borax Conspiracy
14 pages
The Secret Language of Attraction
PDF
86% (108)
The Secret Language of Attraction
278 pages
How To Develop and Write A Grant Proposal
PDF
83% (542)
How To Develop and Write A Grant Proposal
17 pages
Penis Enlargement Secret
PDF
60% (124)
Penis Enlargement Secret
12 pages
Workbook For The Body Keeps The Score
PDF
89% (53)
Workbook For The Body Keeps The Score
111 pages
Donald Trump & Jeffrey Epstein Rape Lawsuit and Affidavits
PDF
83% (1016)
Donald Trump & Jeffrey Epstein Rape Lawsuit and Affidavits
13 pages
KamaSutra Positions
PDF
78% (69)
KamaSutra Positions
55 pages
7 Hermetic Principles
PDF
93% (30)
7 Hermetic Principles
3 pages
27 Feedback Mechanisms Pogil Key
PDF
77% (13)
27 Feedback Mechanisms Pogil Key
6 pages
Frank Hammond - List of Demons
PDF
92% (92)
Frank Hammond - List of Demons
3 pages
Phone Codes
PDF
79% (28)
Phone Codes
5 pages
36 Questions That Lead To Love
PDF
91% (35)
36 Questions That Lead To Love
3 pages
How 2 Setup Trust
PDF
97% (307)
How 2 Setup Trust
3 pages
The 36 Questions That Lead To Love - The New York Times
PDF
94% (34)
The 36 Questions That Lead To Love - The New York Times
3 pages
100 Questions To Ask Your Partner
PDF
78% (36)
100 Questions To Ask Your Partner
2 pages
Satanic Calendar
PDF
25% (56)
Satanic Calendar
4 pages
The 36 Questions That Lead To Love - The New York Times
PDF
95% (21)
The 36 Questions That Lead To Love - The New York Times
3 pages
14 Easiest & Hardest Muscles To Build (Ranked With Solutions)
PDF
100% (8)
14 Easiest & Hardest Muscles To Build (Ranked With Solutions)
27 pages
Jeffrey Epstein39s Little Black Book Unredacted PDF
PDF
75% (12)
Jeffrey Epstein39s Little Black Book Unredacted PDF
95 pages
1001 Songs
PDF
69% (72)
1001 Songs
1,798 pages
The 4 Hour Workweek, Expanded and Updated by Timothy Ferriss - Excerpt
PDF
23% (954)
The 4 Hour Workweek, Expanded and Updated by Timothy Ferriss - Excerpt
38 pages
Zodiac Sign & Their Most Common Addictions
PDF
63% (30)
Zodiac Sign & Their Most Common Addictions
9 pages
CPython Internals
PDF
100% (1)
CPython Internals
385 pages
Linux For Developers - Jumpstart Your Linux Programming Skills (PDFDrive) PDF
PDF
100% (3)
Linux For Developers - Jumpstart Your Linux Programming Skills (PDFDrive) PDF
224 pages
The UNIX Programming Environment PDF
PDF
100% (1)
The UNIX Programming Environment PDF
370 pages
Lisp For The Web
PDF
100% (2)
Lisp For The Web
45 pages
Use VIM Like A Pro
PDF
100% (1)
Use VIM Like A Pro
28 pages
The Reasoned Schemer
PDF
100% (2)
The Reasoned Schemer
177 pages
Makefile Tutorial
PDF
100% (1)
Makefile Tutorial
22 pages
Racket Guide
PDF
100% (1)
Racket Guide
336 pages
Lisp Hackers
PDF
100% (4)
Lisp Hackers
77 pages
Emacs For Writers
PDF
No ratings yet
Emacs For Writers
23 pages
Sed - Awk
PDF
No ratings yet
Sed - Awk
7 pages
Structured Programming, Dahl, Dijkstra, Hoare, Academic Press 1972
PDF
100% (7)
Structured Programming, Dahl, Dijkstra, Hoare, Academic Press 1972
234 pages
Use Vim Like A Pro
PDF
No ratings yet
Use Vim Like A Pro
19 pages
Awk Tutorial
PDF
100% (1)
Awk Tutorial
85 pages
Perl Language
PDF
100% (1)
Perl Language
141 pages
The VIM Book (Unknown Author)
PDF
100% (22)
The VIM Book (Unknown Author)
572 pages
Vim From Essentials To Mastery 2011
PDF
No ratings yet
Vim From Essentials To Mastery 2011
294 pages
Lisp Tutorial PDF
PDF
0% (1)
Lisp Tutorial PDF
28 pages
Perl Tutorial PDF
PDF
No ratings yet
Perl Tutorial PDF
258 pages
How To Make Mistakes in Python
PDF
No ratings yet
How To Make Mistakes in Python
82 pages
LISP in Small Pieces
PDF
25% (4)
LISP in Small Pieces
11 pages
Ansi C Balaguruswamy C1
PDF
No ratings yet
Ansi C Balaguruswamy C1
15 pages
Using C Int Unix System
PDF
No ratings yet
Using C Int Unix System
242 pages
Head First PHP & Mysql
PDF
No ratings yet
Head First PHP & Mysql
813 pages
MASM611 - Programmer's Guide
PDF
100% (2)
MASM611 - Programmer's Guide
520 pages
Vim Tutorial
PDF
100% (3)
Vim Tutorial
65 pages
© Nex-G Exuberant Solutions Pvt. LTD
PDF
No ratings yet
© Nex-G Exuberant Solutions Pvt. LTD
283 pages
Unix Administracion
PDF
No ratings yet
Unix Administracion
1,200 pages
Python 201: Intermediate Python (Michael Driscoll)
PDF
No ratings yet
Python 201: Intermediate Python (Michael Driscoll)
30 pages
Ruby Notes For Professionals
PDF
No ratings yet
Ruby Notes For Professionals
236 pages
Let Over Lambda
PDF
100% (3)
Let Over Lambda
124 pages
Parallel Programming (Wilkinson)
PDF
No ratings yet
Parallel Programming (Wilkinson)
485 pages
The Seasoned Schemer
PDF
100% (3)
The Seasoned Schemer
225 pages
Learning VIM Gently - Sujata Biswas
PDF
100% (2)
Learning VIM Gently - Sujata Biswas
52 pages
Unix Programmers Manual
PDF
100% (1)
Unix Programmers Manual
404 pages
Anization and Design The Hardware Software Interface 3rd
PDF
100% (6)
Anization and Design The Hardware Software Interface 3rd
684 pages
JavaScript For Assholes (Sample)
PDF
100% (2)
JavaScript For Assholes (Sample)
29 pages
GNU Emacs Reference Card
PDF
No ratings yet
GNU Emacs Reference Card
651 pages
The Unix Programming Environment PDF
PDF
No ratings yet
The Unix Programming Environment PDF
369 pages
(Prentice-Hall Software Series) Brian W. Kernighan, Rob Pike - The UNIX Programming Environment-Prentice-Hall (1984)
PDF
No ratings yet
(Prentice-Hall Software Series) Brian W. Kernighan, Rob Pike - The UNIX Programming Environment-Prentice-Hall (1984)
369 pages
Unix Programming Environment
PDF
No ratings yet
Unix Programming Environment
369 pages
The UNIX Programming Environment - Brian W. Kernighan, Rob Pike
PDF
No ratings yet
The UNIX Programming Environment - Brian W. Kernighan, Rob Pike
369 pages
__pg_bca_computer Applications_10154 Bca Unix & Shell Programming Lab Final_3555
PDF
No ratings yet
__pg_bca_computer Applications_10154 Bca Unix & Shell Programming Lab Final_3555
80 pages
UNIX and Shell Programming (Zer07)
PDF
No ratings yet
UNIX and Shell Programming (Zer07)
734 pages
UNIX
PDF
No ratings yet
UNIX
258 pages
UNIX Programmer's Manual
PDF
No ratings yet
UNIX Programmer's Manual
336 pages
unix notes.docx
PDF
No ratings yet
unix notes.docx
66 pages
Unix and Shell Programming (@dcoder)
PDF
100% (1)
Unix and Shell Programming (@dcoder)
206 pages
Unix Programmer'S Manual: Fourth Edition
PDF
No ratings yet
Unix Programmer'S Manual: Fourth Edition
282 pages
UNIX Module 1 notes
PDF
No ratings yet
UNIX Module 1 notes
39 pages
CCS 3105-Systems Programming - 1
PDF
No ratings yet
CCS 3105-Systems Programming - 1
40 pages
Unix Operating Systems
PDF
No ratings yet
Unix Operating Systems
11 pages
Reading # 1 - UNIX OS Basics
PDF
No ratings yet
Reading # 1 - UNIX OS Basics
17 pages
Introduction To UNIX: Motivate The Use of UNIX Introduce Basic UNIX Features (E.g. Using Directories, Files) Introduce
PDF
No ratings yet
Introduction To UNIX: Motivate The Use of UNIX Introduce Basic UNIX Features (E.g. Using Directories, Files) Introduce
48 pages
Unix Prog Design
PDF
No ratings yet
Unix Prog Design
7 pages
Unix Programming (Code:18CS56) : Presented by
PDF
No ratings yet
Unix Programming (Code:18CS56) : Presented by
132 pages
Cat - V Considered Harmful
PDF
No ratings yet
Cat - V Considered Harmful
7 pages
Hardware Requirements For Unix
PDF
No ratings yet
Hardware Requirements For Unix
42 pages
UNIX For Users Handout
PDF
0% (1)
UNIX For Users Handout
129 pages