LinuxFest Northwest 2013

Bellingham, WA April 27th & 28th

Platinum Sponsors

Beginning Shell Scripting with Bash

morris's picture

The Shell (bash) is a command-line interface for invoking other programs on the Linux system.  It is a also a powerful programming language for controlling complex job flows using pipelines and conditional/looping constructs.  Combined with the GNU coreutils programs and perhaps a few simple filter programs written in Perl or Python, complex programs can be composed in just a few lines.

This session will provide a live demo showing how fairly complex systems can be built from the available primitive operations.  For example, to count down the top ten words (Letterman-style) occurring in a file, say mydata.txt, you may type this command line:

cat mydata.txt | sed -r -e 's/[^A-Za-z]+/\ /g' | sed -e '/^$/d' | sort | uniq -c | sort -n -r | head -10 | cat -n | tac

Better yet, save it in a script file, that you can reuse:

#! /bin/bash cat $* | sed -r -e 's/[^A-Za-z]+/\ /g' | sed -e '/^$/d' | sort | uniq -c | sort -n -r | head -10 | cat -n | tac

Looks complex and possibly even slightly intimidating at first, but we'll build it up piece by piece.


Slides are available at:

Demo examples:


About the presenter

Morris Bernstein is an experienced software engineer, most recently Founder and President of Systems Deployment, LLC ( ), a training and consulting service focusing on Open Source Software .  He is currently teaching Data Structures and Algorithms at UWB ( ).  For additional information, consult his linkedin profile:

Experience level: 




Session Time Slot(s): 

Saturday, April 27, 2013 - 10:00 to 10:50




So, not to be overly nit-picky, but your examples begin with a glaring "useless use of cat". Instead of running can on mydata.txt, just run sed on it directly.

re: uuoc

Meh.  As I mentioned on the slide, cost of an extra process vs. readability enhancement of a left-right scan of a complex pipeline .  YMMV.  Besides, it makes it easy to replace specific file name on the command line with the more general $* in the saved script.