Chapter 2. Introducing Shell Scripts

Chapter 1 introduced the shell, a program that patiently awaits your input in the form of commands. These commands range from a simple ls command to complex command lines made up of multiple commands. Each shell, such as bash, ksh, or csh, requires a slightly different syntax for entering commands, although the basics are very similar. Commands often require command-line options as arguments. All of this can make for complex commands.

Furthermore, you often need to issue a number of commands to accomplish your task. Add this all together and you can see why Unix has the reputation for being hard to use.

Shell scripts help slice through this mess. Shell scripts can hide the complex command syntax, specialized command-line options, and the long directory paths needed for many commands. Shell scripts can gather multiple commands together into one script and thereby act as a single command.

But shells aren't the only way to write scripts. Specialized scripting languages provide another means to write scripts for your system. These specialized languages include Perl, Python, and Tcl.

This chapter introduces shell scripts, as well as writing scripts to interact with the user. It addresses other scripting languages and the tools needed to create your own scripts.

This chapter covers the basics for shell scripts, including:

  • Writing your first scripts

  • Choosing a text editor for creating your scripts

  • Writing scripts to remember strange commands, commands you won't ...

Get Beginning Shell Scripting now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.