Although UNIX Shell Programming is very traditional topic of computer science, it is key to successful projects in almost every new technology. Whether you want to perform repeated tasks in predictable manner or interested in automation, shell programming is your friend. In this shell programming course, you will learn many topics in this course as outlined below.
Course Objectives
- Understanding how shell scripts work and writing simple to complex shell scripts
- Automating tasks under Linux/Unix
- I/O Redirection, Variables
- Using control structure in shell scripts
- Using functions
- Debugging shell scripts
Course Outline
Module 1: Introduction to Shell Scripting
- Why Use Scripts, How Scripts Help in improving efficiency, and automation.
- Introduction to Shell
- Shell internal and external commands
- Return codes
- How Shell Works
- Types of shells available in UNIX systems
- Anatomy of a Shell Script
- Commands, variables, and control structures.
Module 2: Writing First Shell Program
- Three steps of creating and executing shell scripts (script file, permissions, execution)
- Comments and order of execution
- Sub shells and scope of variables
- Creating and exiting of sub shells.
- Ways to Execute a Shell Script
- Making shell file executable, using bash <script> and using dot notation and source command.
- Using Quotes and Special Characters
- Background and Foreground Processes
- Shell Environment Files
- Changing and Switching Shells
- Common Pitfalls of Shell Programmers
Module 3: I/O Redirection and Pipes
- Standard Input, Output, and Error redirection
- Pipes and filters
- grep
- cut
- SED and AWK
- Reading and writing to files
Module 4: Working with variables in shell scripts
- Why use variables
- Creating and using variables
- Special variables
- Taking arguments from command line
- Environment variables
Module 5: Conditions, Arithmetic and String Comparison
- Multiple ways for testing conditions
- Arithmetic and String comparisons
- Logical operators
Module 6: Flow Control Structures
- The if-else class of flow controls
- The for loop
- The case structure
- The while and until loops
- Select statement
- Exiting a control structure
- Nesting
Module 7: Advanced Operations, Arrays and Lists
- Creating arrays and lists
- Indexes
- Using arrays in control structures and loops
- Array elements count, length
- Searching and replacing
- Adding and removing array elements
- Copying arrays
- Reading files
Module 8: Using Functions
- Simple functions
- Parameters
- Exit codes
- Return
Module 9: Script Debugging
- Debugging the whole scripts with –x
- Debugging parts of script with “set –x” and “set +x” within script.
Pre-Requisites
Basic knowledge of Linux operating system is required for this course. You should be running Linux either on your computer or a virtual machine. The easiest way of running virtual machine is installing it on Virtual Box. Basic knowledge of control structures like if-then-else is also a plus. You should know how to login to Linux and set permissions for files (use of chmod command on Linux).
Course Benefits
This course will enable you to write UNIX shell scripts to automate routine tasks, run commands at certain times and be more productive in your day-to-day life. Shell scripts, when used in combination with cron utility can significantly reduce manual work. If you are a programmer or a system administrator responsible for large number of machines, this course is for you.