Product SiteDocumentation Site

14.4. Shell Scripting Basics

For newcomers to scripting, don’t worry. A script, in this case a shell script, is merely a text file with commands mostly the same as the commands you can type at the keyboard. I’ll point out the differences.
The following section quickly introduce scripting for those new to this venture.

14.4.1. Writing a script

For your first venture, enter the following script into a text file:
rpm -qa | grep rpm
This script has a two-part command. The rpm –qa part queries all RPM packages, as covered in Chapter 3, Using RPM . The grep rpm part finds only packages with rpm in their names. This is a very simple script, but it can serve to show how to work with scripts.
Save this file under the name listrpmpkgs, since this script lists RPM packages.
If you’re new to Linux, you’ll notice there’s no program named Notepad.exe. There are, though, a plethora of Linux text editors to choose from. See Chapter 26, Linux Text Editors and Development Tools for a listing of Linux text-editing tools.