Bash Shell Scripting
Much of the underlying strength of Linux derives from its large collection of text-based tools and utilities, in conjunction with a powerful command and scripting language called the shell. Taken together, this toolset provides a high-level and astonishingly productive scripting environment in which all manner of solutions can be developed by using tools in appropriate combination. These range from simple automation of routine administrative tasks to post-processing, filtering and report generation from system log files or other structured data sources.
This 3-day hands-on course shows you how to use this powerful tool-building philosophy by focussing on the bash shell as a programming language, and on many of the key utilities and text filters. You'll also learn how to read, debug and modify real-world scripts within a Linux distribution. Red Hat Linux is used as a platform for hands-on exercises in the course; however the course is not strongly oriented towards any specific distribution.
The course is valuable for anyone who wishes to become a "power user" of linux at the command line. It will improve the productivity of system administrators, developers, network and database managers, in fact anyone who uses linux regularly. Attendees should have some previous experience using Linux at the command line -- our 2-day course "Introduction to Linux" provides ideal background. Prior exposure to a programming language would also be an advantage.
After completing this course you will be able to:
- Increase your productivity by using Linux tools effectively
- Read, understand and modify existing Linux shell scripts
- Write shell scripts to automate administrative tasks
- Search, sort, process and reformat text using filters
- Construct bespoke solutions using tools in combination
- Simple filters: cat, wc, head, tail, tr, uniq...
- Sorting and searching tools: find, sort, grep, wildcards
- System reporting tools: ls, du, df, ps, netstat, lsof, date ...
- Stream editing with sed
- Building solutions by combining tools
Creating Shell Scripts
- How to create a script
- Writing and reading with echo and read
- Passing arguments (positional parameters) to a script
- Built-in variables and environment variables
- Redirecting input and output
Searching and matching text with regular expressions
- Regular Expression syntax
- Examples using grep
- Other contexts for using regular expressions
- Substitutions using tagged regular expressions in sed and vi
Flow control in the shell
- Conditional execution with if ... else
- Testing exit status of a command
- Testing file properties
- Looping with for, while and until
- Multiway branching using case
Advanced shell features
- Defining functions and aliases
- Command substitution
- Structuring data with arrays
- Command sequencing and grouping
- String operations
- Writing arithmetic expressions
- Handling and sending signals: trap and kill
CHAPTER 6: Using awk to process structured input
- How awk processes lines and fields
- Patterns and actions
- Variables, operators and functions
- Formatted output
- Looping and branching in awk
Putting it all together
- Using pipes and command substitution
- Choosing the right tool for the job
- Incremental development of solutions
- Some common idioms
Dr. Chris Brown
Dr. Chris Brown has been using UNIX as a software developer and system administrator since its pioneering days over 30 years ago, and has used Linux professionally and at home for about 10 years. He has written hands-on courses in UNIX/Linux system programming, network programming, PHP, and distributed computing, and has edited and provided instructional design support for many others.
Dr. Brown has taught UNIX and Linux extensively for more than 20 years, in Europe, USA, Canada, India, Hong Kong and Brazil. He provided in-depth technical training on SUSE Linux to Novell’s consultants and IT engineers. He developed training content for Canonical’s “Ubuntu Certified Professional” training and wrote their “Deploying Ubuntu Server” course, and was master trainer for their train-the-trainer program. He is author of the book “UNIX Distributed Programming” published by Prentice Hall, and of “SUSE Linux” published by O’Reilly. He also writes a regular column for the UK magazine “Linux Format”.
Dr Brown is an ardent supporter of Linux and the Open Source movement and brings an enthusiasm, experience, depth of knowledge, and humour to the classroom to make for an effective and enjoyable learning experience. Chris holds a BA in theoretical physics, an MA, and a Ph.D. in particle physics, all from Cambridge University. He also has RedHat RHCE, Novell NCLP and Ubuntu UCP qualifications and is a Ubuntu Certified Instructor.