This is a collection of hints and tips that I have written up over time; you can return to the main tutorial for the main "how to" of shell scripting, or browse the articles below for individual tasks, problem areas, gotchas, and tips.
This section provides some worked examples of shell scripting code, inspired by real-world scenarios.
The problem with using shell functions to return integers
An apparently contradictory position - how do you make a shell script abort on errors, but be able to check for errors like "grep foo /etc/hosts" and act accordingly?
Using Bash's pattern matchin to implement the well-known strstr() function.
This function uses Bash's simple built-in integer mathematical capabilities to display a duration (in seconds) in a more human-readable form
Using GNU Date to work out how many days until a given event (such as Christmas, 25th December)
A useful way of expanding lists automatically. Useful for Bart Simpson, useful for you.
A useful way of automatically expanding lists of numbers and characters. With Bash, you don't need to type "for x in 1 2 3 4 5", or do lots of other laborious typing. It can expand all sorts of numbers, and letters, for you, in ways that you probably never knew.
Normally you only get the exit status of the last command in a pipeline - this way, you can get the status of any command in a pipline of any length
Books and eBooks
You can mail me with this form. If you expect a reply, please ensure that the address you specify is valid. Don't forget to include the simple addition question at the end of the form, to prove that you are a real person!