Scripting Languages

A very large part of the power of Linux is made possible through the use of scripting languages. Scripting languages harness the power inherent in the Linux Command Line Interface (CLI) by allowing system administrators to automate long,  repetitive, and frequently used sequences of commands.

Each shell, including the default shell for most Linux distributions, the BASH shell have many built-in commands that provide a complete programming environment, including the use of variables, and many logical comparative operations that allow program sequence control.

Some folks, especially some of  those who work in compiled languages, tend to dismiss scripting as not being true programming. Nothing could be further from the truth.

Scripting languages all have the same elements as any compiled languages. They also allow the programmer to take advantage of many of the shell and operating system programs that are already available. For example, the following BASH command line program is designed to list each user ID that is currently logged into the system.

echo `who | awk '{print $1}' | sort | uniq` | sed "s/ /, /g"

Because users may be logged in multiple times, this one line program only displays each ID once, and separates the IDs with commas. To program this in the C language would require may thousands of lines of code. The table below shows the number of lines of code in each of the CLI commands used in the above BASH program.


Table 1: The Power of the CLI
Command Source Lines of Code
echo 177
who 755
awk 3412
sort 2614
uniq 302
sed 2093
TOTAL 9353


So you can see that the BASH script above is the equivalent of over 9,000 lines of C program code. And it takes far less time to write the BASH script.

This section of the DataBook for Linux Administrators covers some of the more interesting bits of code I have found or written, and which may help you to solve a problem of your own.

There are plenty of books available that cover the BASH shell itself ans well as programming using BASH. I will not try to create a programming text here. But I do hope to give you an idea of some of the really cool things that you can do using the BASH scripting language in particular.

On-line resources

Here are links to some on-line resources relating to shell scripting. All of the ones I have listed so far are free in all of the Open Source senses of the word.

Name URL Description
Advanced Bash Scripting This on-line document covers many of the advanced aspects of BASH scripting.

Leave a Reply