Previous | Table of Contents | Next |
DESCRIPTION
This module discusses the different aspects of how UNIX and the shell handle commands. There are five areas of discussion:
SIMPLE COMMAND SYNTAX
This section describes the syntax used to invoke a single UNIX program or utility, i.e., simple command. The following example explains the syntax in detail.
name [ -option ... ] [ cmdarg ... ] where:
[] | Brackets enclose an option or cmdarg that is optional. |
... | Periods indicate multiple option s or cmdarg s may follow. |
name | Is the filename or full path of an executable command. |
option | Preceded by a - (hyphen). Must be one of the following. |
noargletter ... | A single-letter option. Multiple noargletter s can be grouped after one - . Perhaps explaining the noargletter word would help. The noarg part means no arguments will follow the letter . | |
argletter optarg[,...] | A single-letter option requiring an option argument. This is to say an argument will follow the option. Bascially, the option informs the program how to use the following argument. | |
optarg | An optarg is a character string that is an argument to the previous argletter option. See rule 8 for further syntax rules. |
|
BSD (Berkeley) |
---|
Command options in BSD may have to be separated by spaces. For example, on System V you might have -aik, whereas on BSD you would have to specify -a -i -k. Unfortunately, BSD has not implemented a standard on command line formats. Check the INTRO section of your system User s Reference Manual for command definitions. |
|
cmdarg | A character string not beginning with a - . Often a filename path. A - by itself represents the standard input. |
A vertical bar may be placed between parameters to create a conditional or selection of parameters. Meaning either the preceding parameter or the following parameter may be used but not both. |
The long form of a command is written as follows :
name [ -noargletter ... ] [ -argletter optarg ... ] [ cmdarg ... ] The following example is described to help you understand how the shell interprets a command. date [ mmddhhmm[yy] ] [ +format ]
The command name is date . The syntax shows that all parameters are optional. It is not necessary to provide any options. If the first argument is used, then yy is optional. The vertical bar represents an or condition in the parameter list. Therefore, either the first parameter or the second one can be used but not both at the same time.
Another command might be worth looking at:
cat [ - ] [ -su ] [ -v [ -et ] ] [ file_list ]
The command name is cat . All parameters are optional. The - must be surrounded by blanks . The -v must be specified if either the -e or -t option is specified. The s , u , v , e , and t options may all be placed after the same hyphen (-). The command syntax is intended to show the dependencies of arguments and options, which is not necessarily the final format.
Command Syntax Rules
The following list of rules will be enforced on all releases of UNIX System V from Release 3.0 and later; although, there are some commands that existed before the 3.0 release that do not conform to these exact rules. The getopts command provides command parsing for shell procedures. It will check for legal options. It supports all but rules 1 and 2, which must be enforced by the command name itself.
SHELL COMMAND SYNTAX
The shell s sophisticated programming language allows complete control of command execution and combination of commands. The shell supports multiple types of commands providing for a flexible and powerful command and programming language.
Simple Commands
A simple command is a list of words. The general format of a simple command follows. For a complete description refer to the Simple Command Syntax section of this module.
command options arguments
The first word is the name of the program to be executed. All remaining words are passed to the program as positional arguments. The first word equates to positional parameter 0. The following example illustrates this format.
cj> cat -s file
cat is positional parameter 0, -s is positional parameter 1, and file is positional parameter 2.
Previous | Table of Contents | Next |