Understanding Basic Shell Script Construction
The first thing you’ll need to do when creating a shell script is to define which shell you want to use to interpret the script.
You might have a particular reason for choosing one shell over another. That’s something we’ll talk about in Chapter 19, Shell Script Portability, and Chapter 22, Using the Z Shell.
You’ll define the shell to use as the interpreter in the shebang line, which is the first line of the script. It will look something like this:
#!/bin/bash
Normally of course, a line that begins with the #
sign would indicate a comment that would be ignored by the shell. The shebang line--and please don’t ask me why it’s called that--is an exception to that rule. In addition to defining a specific shell that you want to use, such as /bin/bash
or /bin/zsh
, you can also define the generic /bin/sh
shell to make your scripts more portable, so that they’ll run...