Programmering - Shellscriptsprogrammering
(4 dagar )

Linux/UNIX Shell Script Programming


This is a 4 days class teaching Linux/Unix shell script development and advanced command tasks. The class also contain basics of SED and AWK.

Users/Developers of Unix/Linux discover that using advanced commands, shell features and shell scripts, improves efficiency and productivity as well as enhancing their use of Unix. However, most users discover these capabilities in an ad-hoc and inefficient way, learning by trial and error and without understanding the concepts behind the features they use. This class deals comprehensively with the capabilities of the Unix shell and the utilities commonly used in the development of shell scripts (interpreted programs) and building applications with make.

The class is run using the basic shell or bash shell, which is rapidly becoming the shell of choice for most users of Linux.

The training concentrates on the common approach to the variants of Unix/Linux whilst looking at some specific areas of Linux and shells (bash). This class is particularly suitable for those who are developers and run Linux based systems.

Target & Target group

Programmers and analysts operating in UNIX/Linux environments, as well as UNIX/Linux system and network managers. 

On completion of this class, students should be able to:

  • Use all significant features of the UNIX/Linux shell
  • Implement advanced variable and array manipulation
  • Develop shell scripts that contain advanced decision making constructs
  • Use the tracing features to speed the development of shell scripts
  • Implement advanced data stream handling by using co-process Communication
  • Incorporate functions in script design
  • Write reliable, maintainable and efficient shell scripts
  • Make user scripts appear and behave as integral system interpreted programs
  • Understand the existing system scripts, thus enhancing knowledge of the system
  • Common use of sed and awk in scripts.
  • Create and use the make command to install/update/uninstall applications
  • Create and use RedHat rpm packages to install/update/uninstall applications

Class Style
All lectures have an accompanying practical session relating not only to the newly-covered material, but building on material and solutions from earlier sessions allowing realistic examples to be considered. The practical sessions account for approximately half of the class time. Hard copy and on-line solutions to all exercises are provided. The class is about 50% theory and 50% practical exercises.

Delegates must have a good working knowledge of the Unix system. This can be gained by attending to a ( RedHat) Unix basic class . Some practical understanding of programming concepts is also required. Typically delegate skills will include a working knowledge of Unix commands and utilities, proficiency in using a generic Unix/Linux file editor, preferably vi, and familiarity with programming concepts, such as batch processing, loops, decision-making constructs. 


Class Content


What is a shell?: Types of shell

Redirection and pipes; Wildcards; Creating shell scripts; The .profile file; Grouping commands and background execution

Tilde expansion; The whence command; Quoting; Using aliases; The ENV file; Here documents; Job control

Setting and getting variables; Using ${} and $(); Exported, read only and predefined variables; Length of variables

Positional parameters; Counting parameters; Using shift; Parameters and set

Making Decisions
Exit status; If-then; If-then-else; If-then-elif-then-else; Tests; The case statement; Logical tests; More pattern matching

The while and until loops; The for loop; Break and continue; The select command; I/O redirection and loops; The getopts command

Arithmetic in the Shell
Declaring integer variables; Operators; The let keyword; Making arithmetic tests; Using other bases

Writing functions; Return values from functions; Autoload; Local versus global variables; Listing and removing functions

Debugging in the Shell
Setting the xtrace option; The trace prompt; Tracing functions; Traps

Handling Arrays
Accessing elements; Setting elements; Counting the elements in an array

Professional Scripts
Organising project files; Enhancing script behaviour with getopts

More Complicated I/O
Putting files onto file descriptors; Read and print revisited; Co-processes

Introduction to sed and awk
Simple instructions; Script files; Regular expressions; Addressing in sed; Grouping commands in sed; The main awk loop; Referencing fields; Predefined awk values; Variables, operators; 

The make command

Installing and setting up software with the make command. Editing and understanding the Makefile and configuration script. Deploying applications with make and rpm.

Creating RPM's

Installing and setting up software with the rpm command. Setting up your enviroment to create rpm packages. Editing and understanding .spec files for RPM installations.

Class material

Our own material contains of one map with theory/powerpoint/exercises.

English: Linux/Unix Shell Scripts

English: Exercises Linux/Unix Shell Scripts

Recommended books

English: Unix Shell Programming, 3rd Edition ISBN: 0672324903