Advanced bash scripting 2017
Welcome to the web page for the 2017 incarnation of the course
"advanced bash
scripting". Feel free to take a look at the
course abstract or the learning objectives
to find out what we have planned.
As we go along I will update and extend the teaching material,
so feel free to check back later as well.
If you want to participate in the course, I would kindly ask you to register in advance to reserve yourself a spot.
Time and location
The course will take place from the 6th to the 10th November 2017 at Heidelberg University. We will meet in room 3.104 (PC-Pool 2), Mathematikon (INF 205) on the third floor. The course is structured as a full day course running from 9:30am till about 5pm each day with some breaks for lunch and coffee in between.
Please note, that we will need to change into seminar rooms without computers a couple of times during the course and therefore cannot rely only on the computers in the computer pool for the exercises. You are kindly asked to bring your own laptop to the course for that reason.
Abstract
The bash
shell is the default shell in almost all major UNIX and LinuX
distributions, which makes learning about the bash
scripting language
pretty much unavoidable if one is working on a UNIX-like operating
system. On the other hand this also implies that writing bash
scripts is
conceptually very simple — essentially like making structured notes
of the commands one would need to type in the shell anyway.
When it comes to more involved tasks and more powerful scripts, however,
taking a deeper look at the underlying operating system is typically required.
After all bash
scripting is all about properly combining the programs
available on the UNIX operating system in a clever way as we will see.
In the first part of the course we will hence revisit some basic
concepts of UNIX-like operating systems and review the set of
UNIX coreutils one typically needs for everyday scripting.
Afterwards we will talk about the bash
shell and its core language features,
including
- control statements (
if
,for
,while
, ...) - file or user input/output
bash
functions- features simplifying code reuse and script structure
The final part will be concerned with the extraction of information
(from files etc.) using so-called regular expressions and programs like
awk
, sed
or grep
.
Learning objectives
After the course you will be able to
- apply and utilise the UNIX philosophy in the context of scripting
- identify the structure of a
bash
script - enumerate the core concepts of the
bash
scripting language - structure a script in a way such that code is reusable in other scripts
- extract information from a file using regular expressions and standard UNIX tools
- name advantages and disadvantages of tools like
awk
,sed
orgrep
,cut
..., and give examples for situations in which one is more suitable than the other.
Prerequisites
Familiarity with a UNIX-like operating system like GNU/Linux and the bash
shell
is assumed.
For example you should be able to
- navigate through your files from the terminal.
- create or delete files or folders from the terminal.
- run programs from the terminal (like some "one-liners").
- edit files using a common graphical (or command-line) text editor
like
gedit
,leafpad
,vim
,nano
, ...
It is not assumed, but highly recommended, that you have some previous experiences with programming or scripting in a UNIX-like operating system.
Laptops for the exercises
Since part of the course will take place in seminar rooms without computers, you will need to bring your own laptops to the course to work on the exercises.
Pretty much any standard Linux or UNIX distribution will have the required software in their repositories. This explicitly includes Debian, Ubuntu, Linux Mint, Arch, Fedora on the Linux side and FreeBSD and MacOS X on the UNIX side. We will install what is needed during the course in case it is not yet on your machine by default anyway.
For Windows computers I recommend using a virtual machine with Linux Mint. Please let me know if you plan to bring along a Windows machine, such that I can prepare some images in advance.
Related courses
This is the second time I teach this course. The notes will be largely based on the old material, which can still be found online.
Last year I taught another course related to UNIX script writing,
namely "Introduction to awk
programming".
It discussed the scripting language awk
in depth,
which we will only briefly consider here.
Teaching material
Link |
---|
Course abstract |
Lecture notes |
Course files (including notes, resources and example files) |
Solutions to the exercises (pdf with comments) |
Solution script files |
Both the lecture notes as well as the script examples are managed
in a public git repository on github.
For the most recent version of the material (including corrected errors
and other updates) you should refer to this repository
or to the DOI 10.5281/zenodo.1038525
.
Feel free to cite this DOI in case you find the course material useful for your work.