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. More detail

; 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. More detail

Previous Top Next

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