Advanced Unix Scripting (2 days)

Synopsis This fast-paced course teaches advanced use of the C shell and awk for scripting. Variables, looping, and conditional constructs are covered in both languages. Various Unix utilities such are find and grep are used throughout.
Target audience This course is designed for anyone who needs to write C shell scripts or perform advanced functions at the command line. This is a course for programmers and administrators; it may be too advanced for casual users.
Prerequisites A basic knowledge of Unix is required for this course. Previous knowledge of the C shell and awk is not necessary, although experience with any high-level language (Perl, C, Fortran, BASIC, etc) is highly desirable.
Lab exercises Each chapter contains relevant, hands-on exercises to provide real-life practice in Unix scripting.

Course Outline

1. C Shell Basics

  • The command line
  • Wild cards
  • Command line history
  • Startup files
  • Common C shell commands

2. Variables and Quoting

  • Defining shell variables
  • Multivalue variables (arrays)
  • Variable modifiers
  • Math calculations
  • Quotes and backslash
  • Environment variables

3. Input and output

  • More about echo
  • Getting command line arguments
  • Reading keyboard input
  • I/O Redirection
  • Pipes

4. Conditional constructs

  • Using AND and OR
  • The if statement
  • The test command and other Boolean expressions
  • File inquiry operators

5. Loops

  • The while loop
  • The foreach loop
  • Early exit from loops

6. Debugging C Shell Scripts

  • Syntax checking
  • Verbose output
  • Echoing lines after expansion

7. Awk basics

  • What is awk?
  • Basic format of an awk script
  • Kinds of tasks appropriate for awk
  • Simple awk I/O
  • Automatic processing of input files

8. Pattern Matching and other line selectors

  • Matching the entire line
  • Matching a field
  • Numeric selectors
  • Counting lines and fields

9. Awk variables

  • Creating variables
  • Built-in variables
  • Normal arrays
  • Associative arrays
  • Setting variables on the command line

10. Output and other actions

  • Simple print statements
  • Using printf for more control
  • Conditionals and loops

11. Useful functions

  • String functions
  • Numeric functions
  • I/O Functions