Search Tillamook Rage
Google Custom Search

1.19.2008

Average Joe Scripting - Introduction

You might be interested in this series of posts if you want to learn more about shell scripting. Knowing more about shell scripting will help you in several areas including how to be more effective with Linux system administration, understanding installation and setup scripts and how to fix them, or knowing what to do when you're having a hard time finding just the right program to fit your need.

One of the main things that I like so much about Linux is the amount of power and flexibility that it gives its users. This is evident in a lot of places on a Linux system, but one of the main areas of interest for me is shell scripting. For the uninitiated among you, the “art” of shell scripting allows you to write a text file that holds commands (like the ones you type in the X terminal window) and then allows you to use a shell to execute them. I'm using the term "shell" here to mean a program that takes text input and then does something with it. Scripting is a huge help in automating system administration tasks, and when coupled with the cron daemon, it takes mundane or repetitive tasks and does them automatically for you. If you're not a hard-core system administrator though, don't lose heart – there are tons of cool things that can be done with shell scripts that all of us can enjoy. Having trouble finding a program that can record your favorite radio show from the Internet to a format you want? No problem, just use a script to combine several programs to get what you want. Setting up several educational computers for your students and don't want to keep doing the same install procedure over and over? Dump all of the commands into a shell script and throw it on a flash drive. Trouble with your droid? Just write a script to...

Ever since I started programming (oh so long ago), good code “modularity” has been one of the goals of most new programming languages. Modularity is the quality of a language or architecture that allows a programmer to write blocks of code that work well together, but are loosely coupled enough that they can be changed or replaced without breaking anything. Each programming block doesn't care about what another one is as long as it gives the right data. It's kind of like calling the operator two different times in a row to get a phone number. You don't care if you get a different operator each time as long as they give you the number you ask for. Shell scripting gives you the ability to pull together completely different applications written in different languages into one cohesive package that does your bidding – which to me is a great model of code modularity.

There's not much more satisfying to me (in geekdom at least) than taking 15 minutes and writing a shell script to do what a $20 to $2000 piece of software would do. Granted, entering your credit card number on a web site takes less time than learning the basics of shell scripting, but that program you just bought will only solve 1 or 2 of your problems, whereas shell scripting will solve most of them at no monetary cost to you.

In this series of posts I'm hoping to not only give you nifty shell scripts that will help you do fun and useful things, but to teach you the basics of how shell scripting works. Along the way, I'll explain when/why/how things work the way they do in a script and some tips and tricks to make life easier. So, please stay tuned for future installments of this series.

Next time - The Anatomy of a Simple Shell Script.

Enjoy!

No comments: