First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

RPI102 RaspberryPi - Introduction to Linux command line tools and utilities and shell programming

Duration: 3 Days

Intended Audience

Attendees should have a basic understanding of Linux, e.g. as might be acquired by attending the Introduction to the RaspberryPi course. You are expected to have a basic knowledge of how to use Linux, both from the desktop and from the command line. You are not expected to be programmers, though a little prior exposure to e.g. Javascript or VBA would not go amiss. As always, a positive attitude to open source software would be most helpful, as would an enthusiasm for exploring and playing around with new technoloties.

Course Overview

The goals of this course are to get build on your basic Linux skills and to introduce you to the world of Shell programming ( or shell scripting as it is often referred to). The course will make use of not only Linux running on the Raspberry Pi, but, also regular Linux running either standalone or on VMWare running on a Window platform. As well as covering the simpler (Ash - A Shell) that is part of Busybox we will also cover the basics of Bash shell programming (Bash being the most common shell found on larger Linux installations). Here, again, we are conforming to our policy of getting more people confident in using Linux. We feel that this is especially important for those in the teaching profession as Linux is, sadly, very under-represented in most schools. There will also be time on the course to ask questions that might have arisen from materials presented in the introductory course.

Linux in particular, and Unix in general have very much of a "Lego" philosophy behind them. The idea is to provide a lot of well designed small tools and components that do one particular job and do it well, and then to provide a mechanism for combining these components to achieve more complex goals. It is the purpose of the shell programming language to provide the means for combining these components together. Think of a shell program as a kind of glue language. When developing shell scripts use will be made of various Linux command line tools and utilities (and there will be a chance to refresh your understanding of these commands and utilities).

Each attendee will be given a RaspberryPi 3 to take with them after the course, and, much more importantly the knowledge and confidence to apply their new found shell programming skills not only to Linux running on a PC or a RasbperryPi, but to other Linux devices also.

Course Benefits

Probably the next daunting task after installing Linux, finding your way around it, and getting to know how to use some of the command and utilities is to learn how to read and write shell scripts.

You'll learn how to write shell scripts to create and process batches of files. You'll also learn something of rapid prototyping - because this is an area that shell programming is good for. You'll gain insights into the Unix philosophy of automating work wherever possible e.g. automating uploading of content to a web server, automating the configuration and installation of applications.

You will also be introduced to the philosophy of mini-langages as exemplified e.g. by sed and awk. Amongst other skills you will learn some quite powerful and useful sed and awk one liners. We will also tell you about Cygwin, which will enable to apply some of your knowledge of Linux command line tools and utilities and shell programming to the Windows environment.

Course Contents

  • Introduction
    • Overview of command line tools and utilities
    • Introduction to Cygwin - bringing Linux tools and utilities to Microsoft Windows
    • Accessing and using manual pages
  • Basic utilities
    • Simple filters: cat, wc, head, tail, tr, uniq
    • Sorting and searching tools: find, sort, grep, wildcards
    • System reporting tools: ls, du, df, ps, netstat, uname, date
    • Stream editing with sed
    • Building solutions by combining tools
  • Searching and matching text with regular expressions
    • Regular Expression syntax
    • Examples using grep
    • Other contexts for using regular expressions
    • Substitutions using tagged regular expressions in sed and vi
  • Creating Shell Scripts
    • Passing arguments to a script
    • Built-in variables and environment variables
    • I/O with echo and read
    • Redirecting input and output
    • Arithmetic and string operations
  • Flow control in the shell
    • Conditional execution with if ... else
    • Testing exit status of a command
    • Testing file properties
    • Looping with for, while and until
    • Multiway branching using case
    • Busybox Ash and Bash compared
  • Advanced shell features - an overview
    • Defining functions and aliases
    • Command substitution
    • Structuring data with arrays
    • Command sequencing and grouping
  • Using sed to process documents
    • How a stream editor works
    • sed as an example mini-language
    • Using sed scripts to modify documents - word substitution, rearrangment of text
    • Using sed to modify tags in HTML documents or XML documents
  • Using awk to process structured input
    • How awk processes lines and fields
    • Patterns and actions
    • Variables, operators and functions
    • Formatted output
    • Looping and branching in awk
  • Putting it all together
    • Using pipes and command substitution
    • Choosing the right tool for the job
    • Incremental development of solutions
    • Some common shell scripting idioms