Shell and Perl Scripting
Shell and Perl Scripting
Overview
-
Looking at Some Shell Scripts
-
Learning the Basics of Shell Scripting in Bash
-
Using Bash Control Structures
-
Perl as a Scripting Language
-
Writing Your First Perl Script
-
Using Variables in Perl
-
Using Arrays
-
Using Operators and Expressions
-
Learning Regular Expressions
-
Using if and unless Statements
-
Using the while Statement
-
Using for and foreach Statements
-
Using the goto Statement
-
Working with Files
-
Writing Perl Subroutines
-
Using a Perl Module
The fundamental philosophy of UNIX, which Linux continues to follow, is to give the user many small and specialized commands, along with the plumbing necessary to connect these commands. By plumbing, I mean the way in which one command's output functions as a second command's input. Bash, the default shell in Linux, provides this plumbing in the form of I/O redirection and pipes. Bash also includes features such as the if
statement, which runs commands only when a specific condition is true, and the for
statement, which repeats commands a specified number of times. You can use these features of Bash when writing interpreted programs called shell scripts.
This chapter shows you how to write simple shell scripts: a collection of shell commands stored in a file. Shell scripts are used to automate various tasks. For example, when your CentOS Linux boots, many shell scripts stored in various subdirectories in the /etc
directory (for example, /etc/init.d
) perform many initialization tasks.
When it comes to writing scripts, the Perl language is also popular among UNIX system administrators. Because you probably are the system administrator of your Linux system, this chapter also introduces you to Perl scripting.
Cross Ref |
Chapter 25 covers Tcl/Tk, another popular scripting language you can use to build applications with a graphical interface. |