Linux / UNIX Bash Scripting - Shell Scripting
This course is to help users of Linux / Unix systems to automate the repetitive tasks they encounter during their daily work using "Shell Scripts" or "Bash Scripts". It is a hands-on course with lots of examples and the goal is to encourage and empower participants to "work smarter not harder". One of the best techniques to employ in this effort is to write a script to carry out repetitive tasks.
- Duration
- 2 days
- Format
- Instructor-led, in person or live online
What the course covers
Prerequisites
Participants should have attended the Linux / Unix User Essentials course or have equivalent skills. The course is aimed at Linux / Unix users, programmers and system administrators.
Linux / UNIX Processes
- What is a Process?
- Process Structure
- The ps Utility
- Options to the ps Utility
- Background Commands (&)
- Killing Background Processes
- Redirecting the Standard Error
Combining Linux commands
- Redirecting input, output and error streams
- Pipe operator
- Command substitutions (``)
- And operator
- Or operator
- Creating a script
Getting Started
- What is a Shell?
- Running Scripts
- Specifying the Script’s Interpreter
- The PATH Environment Variable
- Sub-shells
- chmod +x
- Adding a "shebang" to your script
- Returning a value from your script
Variables
- Shell Variables
- The read Command
- The export Command
- The Shell Environment
- Variable Substitution
- Command Substitution
- Creating an array
Conditional Statements
- The Exit Status of Commands
- Command Line Examples
- The test Command
- The if-then-else Construct
- The elif Construct
- case Statements
Loops
- The for Loop
- The while Loop
- Reading Lines From Files
- Using Arrays with Loops
Functions
- Shell Functions
- Passing Arguments to Functions
- Returning Values from Functions
- Function Libraries
Special Variables
- $$ - PID of Shell
- Command-Line Arguments
- $# - Number of Arguments
- $* - All Arguments
- The shift Command
- The set Command
- Getting Options
Quoting Mechanisms
- Single vs. Double Quotes
- What is a Here Document?
- Using a Here Document
- Here Document Quoting
- Ignoring Leading Tabs
.bashrc
- The Login Process
- Scripts that are run at startup
- Making changes persist a reboot
Advanced Programming
- Shell Arithmetic
- The select Statement
- Terminal Independence in Scripts
- The eval Command
Debugging techniques
- Using echo
- Using Standard Error
- Options for Debugging
- Script Tracing
- Conditional Debugging
Shell Scripting Alternatives
If you are working on very difficult automation tasks, utilising a different language such as Perl or Python could be beneficial. This lesson will demonstrate how some of the techniques encountered so far can be applied to scripts that are written in a different programming language.
Course dates
There are no public dates for this course yet. We also run it on request for teams. Contact us to arrange a date.