Creating Scripts
Christine Bresnahan, Richard Blum · 2012
This chapter covers Bash shell scripts, beginning with the task of creating a new script file. It then describes several important scripting features that help you to perform progressively more complex scripting tasks. Shell scripts are plain-text files, so you create them in text editors such as vi, nano, or pico. You shouldn't use standard word processing programs, such as LibreOffice Writer, to create shell scripts as by default they embed binary code into the final document to indicate fonts, font sizes, and special characters. These binary codes confuse the Linux shell. One of the most basic features of shell scripts is the ability to run commands. You can use both commands that are built into the shell and external commands-that is, you can run other programs as commands. Most of the commands you type in a shell prompt are external commands; they're programs located in /bin, /usr/bin, and other directories on your path. You can run such programs, as well as internal commands, by including their names in the script. You can also specify parameters to such programs in a script. For instance, suppose you want a script that launches two xterm windows and the KMail mail reader program. Although launching several programs from one script can save time in startup scripts and some other situations, scripts are also frequently used to run a series of programs that manipulate data in some way. Such scripts typically do not include the ampersands at the ends of the commands because one command must run after another or may even rely on output from the first.