Linux Shell Scripting (GL375)

H2UW2S

Course ID

H2UW2S

Duration

2 days

Format

ILT/VILT

Overview

This course is designed to provide the skills necessary to automate tasks on a Unix or Linux system. Systems administrators and developers alike can avoid errors and save time and money by replacing repetitive work patterns with shell scripts. Care has been taken to present this course in a format that benefits all students, with or without previous programming experience. Many believe that the best way to learn shell scripting is writing shell scripts. For this reason, lab time is emphasized. Early labs present the scripting process step-by-step, while later labs are presented in a challenge format. While official solutions to each lab task are provided, students are encouraged to create their own before examining the solution. In this way, more experienced students are challenged without overwhelming the less experienced. This course supports Red Hat Enterprise Linux 9.

Course ID

H2UW2S

Duration

2 days

Format

ILT/VILT

  • Audience

    This course is ideal for Unix or Linux system administrators who want to improve their scripting skills.

  • Prerequisites

    There are no prerequisites for this course, but we recommend you have the following experience before attending:

    • A solid understanding of Unix-based systems
    • Proficiency using the Unix or Linux command line
  • Objectives

    After completing this course, you should be able to:

    • Use advanced shell features
    • Write shell scripts
    • Process text files
    • Apply regular expressions
    • Automate tasks with branches and loops
    • Process text with Awk
Divider
  • Course outline

Module 1: Introduction to the Shell


  • Shell script strengths and weaknesses
  • Shells
  • Switching user contexts
  • Example shell script
  • Shell and environment variables
  • Key environment variables
  • Which and type
  • General quoting rules
  • Nesting commands
  • Help from commands and documentation
  • whereis
  • Getting help within the graphical desktop
  • Getting help with man and info
  • $MANPATH, whatis, and apropos

Module 2: Shell Scripting Basics


  • Positional parameters
  • Input and output
  • printf
  • alias
  • Functions
  • Colors in scripts
  • Custom bash prompts

Module 3: Working with Files


  • Communication channels
  • File redirection
  • Piping commands together
  • Doing math
  • Filesystem structures
  • Determining disk usage with df and du
  • cron
  • The crontab command
  • crontab format
  • /etc/cron.*/ directories
  • Sending email with mailx

Module 4: Regular Expressions


  • Searching inside files
  • Regular expression overview
  • Regular expression implementations
  • Regular expressions
  • RE character classes
  • Regex quantifiers
  • RE parenthesis
  • The streaming editor

Module 5: Branching and Looping


  • Exit status
  • Comparisons with test
  • Conditional statements
  • Flow control: case
  • Flow control: while and until loops
  • The borne for-loop
  • Flow control: select

Module 6: Data Munging


  • Text processing with Awk
  • Text sorting
  • Duplicate removal utility
  • Extracting columns of text

Module 7: Security, Whitespace, and Other Gotchas


  • Error handling
  • Gotcha: quoting variables
  • Gotcha: locales
  • Gotchas: maximum command length
  • Gotcha: whitespace in for loops
  • Reading files with while
  • Gotcha: $IFS
  • Gotcha: printing in .bashrc
  • Gotcha: aliases

Appendix A: Challenge

  • Apache configuration files
  • httpd.conf and virtual host configuration

Appendix B: Emacs

  • Emacs
  • The Emacs interface
  • Basic Emacs
  • More Emacs commands

Appendix C: The Secure Shell (SSH)

  • OpenSSH client and server configuration
  • Accessing remote shells
  • Transferring files
  • SSH key management

5 reasons to choose HPE as your training partner

  1. Learn HPE and in-demand IT industry technologies from expert instructors.
  2. Build career-advancing power skills.
  3. Enjoy personalized learning journeys aligned to your company’s needs.
  4. Choose how you learn: in-person, virtually, or online—anytime, anywhere.
  5. Sharpen your skills with access to real environments in virtual labs.

Explore our simplified purchase options, including HPE Education Learning Credits.

  • Lab outline

Lab 1: Introduction to the Shell


  • Shell variables
  • Shell meta-characters
  • Command substitution

Lab 2: Shell Scripting Basics


  • Aliases
  • Bash login scripts
  • Create "userinfo" and "sysinfo" functions

Lab 3: Working with Files


  • Disk and filesystem usage
  • Redirection and pipes

Lab 4: Regular Expressions


  • Pattern matching with regular expressions
  • Extended regular expressions
  • Using regular expressions with sed

Lab 5: Branching and Looping


  • Reporting user statistics
  • Monitoring filesystem usage

Lab 6: Data Munging


  • Create "rmhost" function
  • Create "showenv" function
  • Parsing mail server logs
  • Fixing incorrect files

Lab 7: Security, Whitespace, and other Gotchas


  • Renaming MP3 files
  • Split and display $PATH
  • A tar-based backup

Lab A: Challenge

  • Automated virtual host provisioning

Lab B: Emacs

  • Text editing with Emacs

Recommended for you