Bash Tutorial
Bash Scripting Tutorial
Part 1 - Bash Shell Scripting Basics
Introduction and Basics:
- Introduction Bash Introduction. What is Bash? Bourne Again Shell.
- What is a Shell? Internal and External Commands, Type command, Bash Configuration Files - Startup Files.
- Bash Shell Command Interpreter Bash Command Interpreter.
- Output Streams Standard Input, Standard Output and Standard Error explained.
- Working with Variables Assigning values to variables
- Bash Shell Variables What are Shell Variables?
- Declare Bash Declare statement.
- Bash Scripting Basic Structure Basic Structure of a script.
Filename Wildcard Expansion.
Variable Expansion.
Pre Defined Variables.
Command Substitution.
Quotes: Single Quotes and Double Quotes explained.
Backslash - Escape Character.
Redirection and Pipes.
Using the read command
IFS - Internal Field Separator
env, set, export and unset commands.
Using printf to format output.
Special Shell Variables.
Using the shift command.
Using the eval command.
Changing properties of a variable with declare.
Displaying variable properties with declare -p.
Using comments.
Handling errors - Custom Error logs.
Execute Permissions using chmod.
$PATH explained.
Adding new paths to $PATH.
Part 2 - Bash Shell Scripting
Functions and Blocks of Code:
- Debugging and Return Codes Debugging Bash Scripts. Setting return codes.
- Functions What are functions?
- Here Documents What are Here Documents?
- Here Strings What are Here Strings?
Defining functions.
Working with functions.
Calling functions from within scripts.
Creating a functions library.
Here document examples.
Here String examples.
Part 3 - Bash Shell Scripting Basic Structure
Controlling the flow with conditional processing:
- Bash Scripting if statement Conditional Processing
- Comparing Strings String Comparison tests.
- Bash Scripting Substrings What are Substrings?
- Comparing Numbers Numerical Operators.
- Boolean Operators Logical Boolean Operators.
- Bash Scripting Case Statements Using Case statements to simplify logic within a script.
"if..then..fi"
"if..then..else..fi"
"if ..then..elif..then..else..fi
Testing files and objects with "if" statements.
Using Single Brackets.
Using Double Brackets.
Using Regular Expressions with Double Brackets.
Calculate length of a string.
Extracting a substring from a variable.
Replacing matches within substrings.
Integer Operators.
Testing numeric values and working with numbers.
Logical Negation, Logical AND, Logical OR.
Combining Logical Operators.
Pattern matching with case statements.
Mixed case pattern matching using the case statement.
Part 4 - Using Loops within Bash Shell Scripts
Loops:
- Bash Scripting for loop for loop examples.
- Bash Scripting while loop while loop examples.
- Bash Scripting until loop until loop examples.
- Exiting loops Examples of how to exit a loop.
- Continue Command Examples of how to use the continue command within a loop.
Using the for loop within a script.
Using the while loop within a script.
Using the until loop within a script.
Using the break command to exit a loop.
Continue to the next iteration within a loop.
Part 5 - Number and Arithmetic
Making calculations in Bash:
- Number and Arithmetic Mathematical Operations within Bash.
Arithmetic Operators.
Addition, Subtraction, Division and Multiplication.
Using Modulo command - modulo example.
Exponentiation - exponentiation example.
BC - Bash built in arbitrary precision calculator.
Mathematical Functions.
Invoking the Math library.
Part 6 - Arrays
Working with arrays:
- Working with arrays What is an array?
Array assignment.
Deleting arrays with the unset command.
Bash array example scripts.
Part 7 - Interactive Scripts
Interactive Scripts:
- Getting User Input Create interactive scripts.
- Select Statement Using Select.
Using the read command.
Simple Menus with echo and read commands.
Create interactive menus with select statement.
Combining select and case statements to create menus.