The primary advantages of interfacing to the system through a shell are:
Redirects input away from the keyboard and redirects output to a file or device other than the terminal. For example, input to a program can be provided from a file and redirected to the printer or to another file.
For more information, see the pipeline definition in the "Shells Terms" section.
The following shells are provided with this version of the operating system:
The login shell refers to the shell loaded when you log in to the computer system. Your login shell is set in the /etc/passwd file. The Korn shell is the standard operating system login shell and is backwardly compatible with the Bourne Shell.
The default or standard shell refers to the shell linked to and started with the /usr/bin/sh command. The Bourne shell is set up as the default shell and is a subset of the Korn shell.
The default or standard shell refers to the shell linked to and started with the /usr/bin/sh command. The Korn shell, also known as the POSIX shell, is set up as the default shell. The POSIX shell is called the /usr/bin/psh and is linked to the /usr/bin/ksh command.
The following definitions are
helpful in understanding shells:
|blank||A blank is one of the characters in the blank character class defined in the LC_CTYPE category. In the POSIX shell, a blank is either a tab or space.|
|built-in command||A command that the shell executes without searching for it and creating a separate process.|
|command||A sequence of characters in the syntax of the shell language. The shell reads each command and carries out the desired action either directly or by invoking separate utilities.|
|comment||Any word that begins with pound sign (#). The word and all characters that follow it, until the next new-line character, are ignored.|
|identifier||A sequence of letters, digits, or underscores from the portable character set, starting with a letter or underscore. The first character of an identifier must not be a digit. Identifiers are used as names for aliases, functions, and named parameters.|
|list||A sequence of one or more pipelines separated by one of these four
symbols: semicolon (;), ampersand (&), double ampersand
(&&), or double bar (||). The list is optionally ended by one
of the following symbols: semicolon (;), ampersand (&), or bar
ampersand (| &).
The semicolon (;), ampersand (&), and bar ampersand (|&) have a lower priority than the double ampersand (&&) and double bar (||). The ;, &, and |& symbols have equal priority among themselves. The && and || symbols are equal in priority. One or more new-line characters can be used instead of a semicolon to delimit two commands in a list.
Note: The |& symbol is valid only in the Korn shell.
|metacharacter||Each metacharacter has a special meaning to the shell and causes termination of a word unless it is quoted. Metacharacters are: pipe (|), ampersand (&), semicolon (;), less-than sign (<), greater-than sign (>), left parenthesis ((), right parenthesis ()), dollar sign ($), backquote (`), backslash (\), right quote ('), double quotation marks ("), new-line character, space character, and tab character. All characters enclosed between single quotation marks are considered quoted and are interpreted literally by the shell. The special meaning of metacharacters is retained if not quoted. (Metacharacters are also known as parser metacharacters in the C shell.)|
|parameter assignment list||Includes one or more words of the form
Identifier=Value in which spaces surrounding the equal
sign (=) must be balanced. That is, leading and trailing blanks, or no
blanks, must be used.
Note: In the C shell, the parameter assignment list is of the form set Identifier = Value. The spaces surrounding the equal sign (=) are required.
|pipeline||A sequence of one or more commands separated by pipe (|). Each
command in the pipeline, except possibly the last command, is run as a
separate process. However, the standard output of each command that is
connected by a pipe becomes the standard input of the next command in the
sequence. If a list is enclosed with parentheses, it is carried out as
a simple command that operates in a separate subshell.
If the reserved word ! does not precede the pipeline, the exit status will be the exit status of the last command specified in the pipeline. Otherwise, the exit status is the logical NOT of the exit status of the last command. In other words, if the last command returns zero, the exit status will be 1. If the last command returns greater than zero, the exit status will be zero.
[!] command1 [ | command2 ...]
Note: Early versions of the Bourne shell used the caret (^) to indicate a pipe.
|shell variable||A name or parameter to which a value is assigned. Assign a variable by typing the variable name, an equal sign (=), and then the value. The variable name can be substituted for the assigned value by preceding the variable name with a dollar sign ($). Variables are particularly useful for creating a short notation for a long path name, such as $HOME for the home directory. A predefined variable is one whose value is assigned by the shell. A user-defined variable is one whose value is assigned by a user.|
|simple command||A sequence of optional parameter assignment lists and redirections, in any sequence. They are optionally followed by commands, words, and redirections. They are terminated by ;, |, &, ||, &&, |&, or a new-line character. The command name is passed as parameter 0 (as defined by the exec subroutine). The value of a simple command is its exit status of zero if it terminates normally or nonzero if it terminates abnormally. The sigaction, sigvec, or signal Subroutine in the AIX 5L Version 5.1 Technical Reference: Base Operating System and Extensions Volume 2 includes a list of signal-exit status values.|
|subshell||A shell that is running as a child of the login shell or the current shell.|
|wildcard character||Also known as a pattern-matching character. The shell associates them with assigned values. The basic wildcards are ?, *, [set], and [!set]. Wildcard characters are particularly useful when performing file name substitution.|
|word||A sequence of characters that does not contain any blanks. Words are separated by one or more metacharacters.|
Shell scripts provide an easy way to carry out tedious commands, large or complicated sequences of commands, and routine tasks. A shell script is a file that contains one or more commands. When you type the name of a shell script file, the system executes the command sequence contained by the file.
You can create a shell script using a text editor. Your script can contain both operating system commands and shell built-in commands.
The following steps are general guidelines for writing shell scripts:
By convention, shell scripts that are not set up for use by many users are stored in the $HOME/bin directory.
Note: The operating system does not support the setuid or setgid subroutines within a shell script.
chmod u=rwx script1
Note: You can run a shell script without making it executable if a shell command (ksh, bsh, or csh) precedes the shell script file name on the command line. For example, to run a nonexecutable file named script1 under the control of the Korn shell, type:
When you run an executable shell script in either the Korn (the POSIX Shell) or Bourne shell, the commands in the script are carried out under the control of the current shell (the shell from which the script is started) unless you specify a different shell. When you run an executable shell script in the C shell, the commands in the script are carried out under the control of the Bourne shell (/usr/bin/bsh) unless you specify a different shell.
You can cause a shell script to run in a specific shell by including the shell within the shell script. To run an executable shell script under a specific shell, type #!Path on the first line of the shell script, and press Enter. The #! characters identify the file type. The Path variable specifies the path name of the shell from which to run the shell script. For example, if the first line in a shell script is #!/usr/bin/bsh, the script is run under control of the Bourne shell.
When you precede a shell script file name with a shell command, the shell specified on the command line overrides any shell specified within the script file itself. Therefore, typing ksh myfile and pressing Enter runs the file named myfile under the control of the Korn shell, even if the first line of myfile is #!/usr/bin/csh.
Chapter 6, Files
Chapter 9, File and System Security
Korn Shell or POSIX Shell Commands