O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Linux Shells by Example

Book Description

The complete guide to bash and tsch—PLUS grep, sed, and gawk!

  • Learn Linux shell programming hands-on!

  • Hundreds of classroom-proven examples throughout

  • gawk in-depth! Pattern scanning, text filtering, reporting, and more

  • By best-selling author Ellie Quigley, Silicon Valley's #1 shell programming instructor!

  • CD-ROM: All source code and data files used in the book.

    Learn Linux shell programming hands-on!

    One book is all you need to learn Linux shell programming! Linux Shells by Example is your complete, step-by-step guide to both essential Linux shells-bash and tcsh—and three essential Linux shell programming utilities, grep, sed and gawk. Ellie Quigley—Silicon Valley's top shell programming instructor—starts from scratch and gets you all the way to expert-level techniques! Through hundreds of classroom-proven examples, you'll learn what Linux shells are, what they do, and exactly how they integrate with other Linux utilities and processes. Master creating, running, and debugging shell scripts using grep, sed, gawk, and a whole lot more.

  • bash and tcsh: how they compare, and when to use each

  • gawk in depth: pattern scanning, text filtering, reporting, and other key applications

  • Includes hands-on exercises for every topic

  • Detailed syntax listings, comparison charts, essential information on Linux utilities, and more

  • Whether you're a system administrator, application developer or power user, Linux Shells by Example is the most convenient, cost-effective way to learn Linux shell programming!


    CD-ROM contains all of the source code and datafiles from the book.

    Table of Contents

    1. Copyright
    2. PREFACE
    3. Acknowldgements
    4. About the Author
    5. Introduction to Linux Shells
      1. Why Linux?
      2. Definition and Function of a Shell
      3. System Startup and the Login Shell
      4. Processes and the Shell
      5. The Environment and Inheritance
      6. Executing Commands from Scripts
    6. The Linux Tool Box
      1. Regular Expressions
      2. Combining Regular Expression Metacharacters
    7. The Grep Family (Gnu & Sons)
      1. The grep Command
      2. Extended grep (grep -E or egrep)
      3. Fixed grep (grep -F and fgrep)
      4. Recursive grep (rgrep)
      5. grep with Pipes
      6. grep with Options
      7. Linux Tools Lab 1
    8. The Streamlined Editor
      1. What Is sed?
      2. Versions of sed
      3. How Does sed Work?
      4. Addressing
      5. Commands and Options
      6. Error Messages and Exit Status
      7. sed Examples
      8. sed Scripting
      9. LINUX TOOLS LAB 2
    9. Gawk Utility: Gawk as a Linux Tool
      1. What's awk? What's nawk? What's gawk?
      2. awk's Format
      3. Formatting Output
      4. awk Commands from within a File
      5. Records and Fields
      6. Patterns and Actions
      7. Regular Expressions
      8. awk Commands in a Script File
      9. Review
      10. Linux Tools Lab 3
    10. The Gawk Utility: Evaluating Expressions
      1. Comparison Expressions
      2. Review
      3. Linux Tools Lab 4
    11. The Gawk Utility: Gawk Programming
      1. Variables
      2. Redirection and Pipes
      3. Pipes
      4. Closing Files and Pipes
      5. Review
      6. Linux TOOLS LAB 5
      7. Conditional Statements
      8. Loops
      9. Program Control Statements
      10. Arrays
      11. awk Built-In Functions
      12. User-Defined Functions
      13. Review
      14. Linux Tools Lab 6
      15. Odds and Ends
      16. Review
      17. Linux Tools Lab 7
    12. The Interactive Bash Shell
      1. Introduction
      2. Command Line Shortcuts
      3. Variables
      4. The Bourne Shell Lab Exercises
    13. Programming with the Bash Shell
      1. Introduction
      2. Reading User Input
      3. Arithmetic
      4. Positional Parameters and Command Line Arguments
      5. Conditional Constructs and Flow Control
      6. Looping Commands
      7. Functions
      8. Trapping Signals
      9. Debugging
      10. Processing Command Line Options with getopts
      11. The eval Command and Parsing the Command Line
      12. Bash Options
      13. Shell Built-In Commands
      14. The Bash Shell Lab Exercises
    14. The Interactive TC Shell
      1. Introduction
      2. The TC Shell Environment
      3. Command Line Shortcuts
      4. Job Control
      5. Metacharacters
      6. Redirection and Pipes
      7. Variables
      8. Arrays
      9. Special Variables and Modifiers
      10. Command Substitution
      11. Quoting
      12. Built-In Commands
      13. The TC Shell Lab Exercises
    15. Programming with the TC Shell
      1. Steps in Creating a Shell Script
      2. Reading User Input
      3. Arithmetic
      4. Debugging Scripts
      5. Command Line Arguments
      6. Flow Control and Conditional Constructs
      7. Loops
      8. Interrupt Handling
      9. setuid Scripts
      10. Storing Scripts
      11. Built-In Commands
      12. The TC Shell Lab Exercises
    16. Useful Linux/UNIX Utilities for Shell Programmers
      1. apropos—searches the what is database for strings
      2. arch—prints the machine architecture (see uname -m)
      3. at—at, atq, atrmbatch—execute commands at a later time
      4. awk (gawk)—pattern scanning and processing language
      5. banner—make posters
      6. basename—with a directory name delivers portions of the pathname
      7. bash—Gnu Bourne Again Shell
      8. bc—processes precision arithmetic
      9. biff [ny]—be notified if mail arrives and who it is from
      10. cal—displays a calendar
      11. cat—concatenates and displays files
      12. chfn—change the finger information
      13. chmod—change the permissions mode of a file
      14. chown—change the user and group ownership of files
      15. chsh—change your login shell
      16. clear—clears the terminal screen
      17. cmp—compares two files
      18. compress—compress, uncompress, zcat compress, uncompress files, or display expanded files
      19. cp—copies files
      20. cpio—copy file archives in and out
      21. cron—the clock daemon
      22. crypt—encodes or decodes a file
      23. cut—removes selected fields or characters from each line of a file
      24. date—displays the date and time or sets the date
      25. dd—converts a file while copying it
      26. diff—compares two files for differences
      27. dos, xdos, dosexec, dosdebug—a Linux dos emulator that runs MS-DOS and MS-DOS programs under Linux
      28. df—summarizes free disk space
      29. du-summarizes disk usage
      30. echo—echoes arguments
      31. egrep—searches a file for a pattern using full regular expressions
      32. expr—evaluates arguments as an expression.
      33. fgrep—search a file for a character string
      34. file—determines the type of a file by looking at its contents
      35. find—finds files
      36. finger—displays information about local and remote users
      37. fmt—simple text formatters
      38. fold—folds long lines
      39. ftp—file transfer program
      40. free—displays amount of free and used memory in the system
      41. fuser—identifies processes using files or sockets
      42. gawk—pattern scanning and processing language
      43. gcc, g++—Gnu project C and C++ Compiler (v2.7)
      44. getopt(s)—parses command line options
      45. grep—searches a file for a pattern (See Chapter 3)
      46. groups—prints group membership of user
      47. gzip, gunzip, zcat—compresses or expands files
      48. head—outputs the first ten lines of a file(s)
      49. host—prints information about specified hosts or zones in DNS
      50. id—prints the username, user ID, group name, and group ID
      51. jsh—the standard, job control shell
      52. kill—sends a signal to terminate one or more processes
      53. killall—kills processes by name
      54. less—opposite of more
      55. line—reads one line
      56. ln—creates hard links to files
      57. logname—gets the name of the user running the process
      58. look—displays lines beginning with a given string
      59. lp (ATT, Linux)—sends output to a printer
      60. lpr (UCB, Linux)—sends output to a printer
      61. lpstat (ATT)—prints information about the status of the LP print service
      62. lpq (UCB, Linux)—prints information about the status of the printer
      63. ls, dir, vdir—lists contents of directory
      64. mail—mail, rmail—reads mail or send mail to users
      65. mailx—interactive message processing system
      66. make—maintains, updates, and regenerates groups of related programs and files
      67. man—formats and displays the online manual pages
      68. manpath—determines user's search path for man pages
      69. mesg—permits or denies messages resulting from the write command
      70. mkdir—creates a directory
      71. more—browses or pages through a text file
      72. mtools—utilities to access DOS disks in UNIX
      73. mv—moves or renames files
      74. nawk—pattern scanning and processing language
      75. newgrp—logs in to a new group
      76. news—prints news items
      77. nice—runs a command at low priority
      78. nohup—makes commands immune to hangups and quits
      79. od—dumps files in octal and other formats
      80. pack—pack, pcat, unpack—compresses and expands files
      81. passwd—changes the login password and password attributes
      82. paste—merges same lines of several files or subsequent lines of one file
      83. pcat—(see "pack" on page706)
      84. pine—a Program for Internet News and E-mail
      85. pg—displays files a page at a time
      86. pr—prints files
      87. ping—reports if a remote system is reachable and alive
      88. ps—reports process status
      89. pstree—displays a tree of processes
      90. pwd—displays the present working directory name
      91. quota—displays users' disk usage and limits
      92. rcp—remote file copy
      93. rdate—get the date and time via the network
      94. rgrep—a recursive, highlighting grep program
      95. rlogin—remote login
      96. rm—removes files from directories
      97. rmdir—removes a directory
      98. rsh—starts a remote shell
      99. ruptime—shows the host status of local machines
      100. rwho—who is logged in on local machines
      101. script—creates a typescript of a terminal session
      102. sed—stream editor (seeChapter 4)
      103. size—prints section sizes in bytes of object files
      104. sleep—suspends execution for some number of seconds
      105. sort—sort and/or merge files
      106. spell—finds spelling errors
      107. split—splits a file into pieces
      108. strings—finds any printable strings in an object or binary file
      109. stty—sets the options for a terminal
      110. su—become superuser or another user
      111. sum—calculates a checksum for a file
      112. sync—updates the superblock and sends changed blocks to disk
      113. tabs—sets tab stops on a terminal
      114. tail—displays the tail end of a file
      115. talk—allows you to talk to another user
      116. tar—stores and retrieves files from an archive file, normally a tape device
      117. tee—replicates the standard output
      118. telnet—communicates with a remote host
      119. test—evaluates an expression and check file types
      120. time—displays a summary of time used by this shell and its children
      121. timex—times a command; reports process data and system activity
      122. top—displays top CPU processes
      123. touch—updates access time and/or modification time of a file
      124. tput—initializes a terminal or queries the terminfo database
      125. tr—translates characters
      126. true—provides successful exit status
      127. tsort—topological sort
      128. tty—gets the name of the terminal
      129. umask—sets file-creation mode mask for permissions
      130. uname—prints name of current machine
      131. uncompress—restores files to their original state after they have been compressed using the compress command
      132. uniq—reports on duplicate lines in a file
      133. units—converts quantities expressed in standard scales to other scales
      134. unpack—expands files created by pack
      135. uucp—copies files to another system, UNIX-to-UNIX system copy
      136. uuencode—uuencode, uudecode—encodes a binary file into ASCII text in order to send it through e-mail, or convert it back into its original form
      137. wc—counts lines, words, and characters
      138. what—extracts SCCS version information from a file by printing information found after the @(#) pattern
      139. which (UCB)—locates a command and displays its pathname or alias
      140. whereis (UCB)—locates the binary, source, and manual page files for a command
      141. who—displays who is logged on the system
      142. write—writes a message to another user
      143. xargs—constructs an argument list(s) and executes a command
      144. zcat—uncompresses a compressed file to standard output. Same as uncompress –c
      145. zipinfo—lists detailed information about a ZIP archive
      146. zmore—file perusal filter for crt viewing of compressed text
    17. Comparison of the Shells
      1. tcsh versus csh
      2. bash versus sh
    18. Steps for Using Quoting Correctly
      1. Backslash (see Table C.1):
      2. Single Quotes (see Table C.1):
      3. Double Quotes (see Table C.2):
      4. Combining Quotes:
    19. Index