Basic types of statements in a shell script



Last revision August 6, 2004

Comments
The "pound" or "hash" sign (#) signals the start of a comment. This sign and anything that follows it up to the end of the line is interpreted as a comment for the author and is not executed.

Commands to be executed in a new process
If a line in the script does not begin with one of the reserved keywords that is used for variable operations or flow-control, it is assumed to be a command that you want to execute as a new child process. The entire line is scanned, looking for variables that need to be substituted and wildcards characters ("*", "?", etc) that need to be matched to filenames. After all substitutions are performed, it is executed as if you had typed it at the terminal.

Setting and substituting variable values
Special keywords such as set or the $ symbol indicate a variable is to be set or used.

Flow-of-control: loops, conditionals
Special keywords such as if or foreach are used to start lines in the script that provide flow control or conditional execution.