Duration: 3 days
Price: Contact us for pricing.
Description: This hands on Korn Shell scripting course provides a comprehensive introduction to writing Korn shell scripts. Besides covering fundamental syntax for program flow control, variable assignment and substitution, I/O control, and mathematical expressions, it emphasizes the powerful features that are unique to this shell, including built-in string operators, variable typesetting/conversion, functions, and coprocess communication and control. The creative use of standard UNIX utilities within scripts to solve problems is stressed throughout. The course is designed for the administrators and programmers who are developing, testing, or integrating software on UNIX, as well as for advanced UNIX users.
Prerequisites: Familiarity with UNIX file system and commands
Overview of Topics Covered:
Introduction
- Shells: Bourne, Korn, C, bash
- Korn Shell Environment
- Startup Scripts (.profile, .kshrc)
- Using ENV for automatic environment tailoring
|
|
Korn Shell Command Syntax
- Commands
- Options
- Manipulating Input and Output
- Aliases (alias, unalias)
- How the Shell Finds Commands
- Command History and Editing
|
Variables
- Assigning Values to Variables
- set and Special Variables
- unset
- Built-in Variables Known to Login Shell
- The Environment- Exporting Variables
|
|
The Korn Shell as a Programming
Language
- Data Types (typeset)
- Formatting
- Base Conversion
- Read Only and Other Special Attributes
- Input/Output
- Conditional Logic and Loops
- Functions
- Tests
|
Input/Output
- Basic I/O Features
- String and Field Processing
- Streams and pipes (exec)
- Terminal Information (COLUMNS, LINES, TERM)
- stty
|
|
Shell Scripts
- Creating Scripts
- Executing Scripts
- Passing Arguments to Scripts
- Built-in Variables Known to Scripts
- Setting Variables with read
- Special Characters
- Exiting with exit
- Debugging
|
String Manipulation
- String Comparison
- String Relations
- Concatenation
- Substring Manipulations
- Wildcards and Pattern Matching
|
|
Conditional Branching
- If/Then
- else/elif
- Statement blocks
- case Statement
- Loops (for, while, until)
- Simple Menus (select)
|
Math Operators and Functions
- Dealing with Floating Point Numbers
|
|
Arrays
- Declaring Arrays
- Setting and Retrieving Values
|
Command Line Arguments
- Positional Parameters
- Manipulating Positional Parameters (set, sort, shift)
- Analyzing Switches with getopts
- Options Reserved Variables (OPTARG, OPTIND, IFS)
|
|
Manipulating Files within
Scripts
- File Operations
- Testing Files and Directories
- Changing Protections
|
Overview of File Manipulation
Utilities
- Input/Output Redirection
- Editing a File from a Script
- Scripting with ed or vi
- UNIX Utilities to Manipulate Files
- Regular Expressions
- grep and egrep
- The Stream Editor sed
- sort
- awk
- Other Text File Utilities
|
|
Functions
- Advantages of Functions
- Writing Functions
- Calling Functions
- Functions Arguments
- Returning Values
- Local and Global Variables
- Predefined Functions
- Exporting Functions
- Autoloading Functions
- Returning a Value from a Function
- Scope of Functions
- Examples of Useful Functions
|
Session Control
- Keyboard Suspend Function
- Foreground and Background Jobs (bg, fg, %, jobs, wait, nohup, nice)
- Signals (kill, trap)
- Coprocesses and Pipes
- Error Processing (ERRNO, $?)
- Reserved Variables
|
|
Example Uses of Scripts
- Prototyping
- Daily Backup
- File Selection
- Installation Scripts
- Add a User
- Change all File Extensions
- Prompt for Input
- Accounting
|
Combining Shell Scripts
and Compiled Languages
- Advantages and Disadvantages of the Korn Shell
- Function Libraries
|
|
Scheduling Execution
- sleep
- date
- cron and crontab
|
Using UNIX Utilities to
Talk to Other Users
- who, mail, reply, talk, lpr
|
|
UNIX Utilities to Report
System Status
|