Text-only Table of Contents (frame/ no frame)
(7) Basics Previous Top Next

Basic sh script syntax

The most basic shell script is a list of commands exactly as could be typed interactively, prefaced by the #! magic header. All the parsing rules, filename wildcards, $PATH searches etc., which were summarized above, apply.
In addition:
# as the first non-whitespace character on a line
flags the line as a comment, and the rest of the line is completely ignored. Use comments liberally in your scripts, as in all other forms of programming.

\ as the last character on a line
causes the following line to be logically joined before interpretation. This allows single very long commands to be entered in the script in a more readable fashion. You can continue the line as many times as needed. Less detail
This is actually just a particular instance of \ being to escape, or remove the special meaning from, the following character.

; as a separator between words on a line
is interpreted as a newline. It allows you to put multiple commands on a single line. There are few occasions when you must do this, but often it is used to improve the layout of compound commands.
Example: ex1 display, text

Exit status

Every command (program) has a value or exit status which it returns to the calling program. This is separate from any output generated. The exit status of a shell script can be explicitly set using exit N, or it defaults to the value of the last command run. Less detail
The exit status is an integer 0-255. Conventionally 0=success and any other value indicates a problem. Think of it as only one way for everything to work, but many possible ways to fail. If the command was terminated by a signal, the value is 128 plus the signal value.

Previous Top Next


basics.src  last modified Mar 11, 2005 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College