Course Description
In this two-day hands-on course students learn how to read, write, and debug complex Bash shell scripts.
Course Objectives
Upon successful completion of this course, students will be able to:
- Read and understand Bash shell scripts
- Debug Bash shell scripts
- Customize and extend their user environment with Bash shell scripts
- Create interactive menus with Bash shell scripts
- Use all key language features of the Bash shell: variables, arrays, branches, loops and functions
- Write Bash shell scripts that perform complex file handling, string manipulations and mathematics
Course Benefits
Bash is the default shell for Linux. Students will increase their productivity by taking full advantage of the Bash shell.
Who Should Attend
This course is valuable for system administrators, developers and other computer professionals involved with Linux.
Prerequisite
To ensure your success, we recommend you first take either our Introduction To UNIX course or our Introduction To Linux course, or have the equivalent knowledge. Familiarity with Web browsers, the
vi
editor, and Linux command line interface is assumed. Prior programming experience is highly recommended.Method Of Instruction
Lecture, demonstrations, questions and answers, and numerous hands-on exercises.
Hands-on Exercises
Throughout this course, students perform a series of extensive hands-on exercises including:
- Creating loops and making decisions using
while
andfor
loops- Writing scripts to perform matematical calculations
- Using
eval
for dynamic commands- Handling errors with default values
- Working with arrays
- Breaking a large program into reusable modules using functions
- Manipulating multiple files
- Handling unexpected events with
trap
- Processing command line options
- Building an interactive menu interface using
case
constructs andread
- Building colorful and sophisticated menu interfaces using
dialog
Course Outline
Chapter 1: Using Structured CommandsChapter 2: Handling User Input
if
,then
,elif
,fi
- The
test
command- Compount condition testing
- The
case
command- The
for
command- The
while
command- The
until
command- Nesting Loops
- The
break
command- The
continue
command- Processing the output of a loop
- Specifying default values and error conditions
- Shell arithmetic
- The
select
statement- The
eval
commandChapter 3: Presenting Data
- $$ - PID of the shell
- $# - Number of arguments
- $* - All arguments
- Getting Options
- Reading in command arguments
- The
read
command- The
IFS
command- The
shift
command- The
set
command- Parameter expansion
Chapter 4: Script Control
- File descriptors
- Redirecting input and output
- Using temporary files
Chapter 5: Functions
- Signals
- Running scripts in the background
- Running scripts without a terminal
- The
at
andbatch
commands- The
nice
command- Having
cron
run scripts- Runnings scripts when booting
Chapter 6: Interactive Graphics
- Calling a function
- Passing arguments to functions
- Setting and unsetting parameters
- Defining global and local variables
- Specifying default values and error conditions
- Returning values from functions
- Function declarations
- Passing and returning arrays
- Creating and using libraries
- Using functions on the command line
Chapter 7:
- Creating text menus
- Adding color
- The
dialog
command- Integrating GNOME and KDE into scripts
sed
andawk
Chapter 8: Debugging Techniques
- Multiline commands
- Inserting and appending text
- Pattern replacemnt
- Extracting fields
- String manipulation
- Formatting output
- Using functions
- Using
echo
andprintf
- Using Standard Error
- Script Tracing
- Options for Debugging
- Conditional Debugging