Built-in Commands

   

Korn Shell: Unix and Linux Programming Manual, Third Edition, The
By Anatole Olczak

Table of Contents
Appendix E.  Korn Shell Man Page


The following simple-commands are executed in the shell process. Input/Output redirection is permitted. Unless otherwise indicated, the output is written on file descriptor 1 and the exit status, when there is no syntax error, is zero. Except for :, true, false, echo, command, newgrp, and login, all built-in commands accept ?/span> to indicate end of options. They also interpret the option -? as a help request and print a usage message on standard error. Commands that are preceded by one or two § symbols are special built-in commands and are treated specially in the following ways:

  1. Variable assignment lists preceding the command remain in effect when the command completes.

  2. I/O redirections are processed after variable assignments.

  3. Errors cause a script that contains them to abort.

  4. They are not valid function names.

  5. Words following a command preceded by §§ that are in the format of a variable assignment are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and field splitting and file name generation are not performed.

§: [arg. . . ]

The command only expands parameters.

§. name [arg. . . ]

If name is a function defined with the function name reserved word syntax, the function is executed in the current environment (as if it had been defined with the name() syntax.) Otherwise if name refers to a file, the file is read in its entirety and the commands are executed in the current shell environment. The search path specified by PATH is used to find the directory containing the file. If any arguments arg are given, they become the positional parameters while processing the . command and the original positional parameters are restored upon completion. Otherwise the positional parameters are unchanged. The exit status is the exit status of the last command executed.

§§ alias [-ptx] [name[=value] ] . . .

alias with no arguments prints the list of aliases in the form name=value on standard output. The -p option causes the word alias to be inserted before each one. When one or more arguments are given, an alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias substitution. The obsolete -t option is used to set and list tracked aliases. The value of a tracked alias is the full pathname corresponding to the given name. The value becomes undefined when the value of PATH is reset but the alias remains tracked. Without the -t option, for each name in the argument list for which no value is given, the name and value of the alias is printed. The obsolete -x option has no effect. The exit status is non-zero if a name is given, but no value, and no alias has been defined for the name.

bg [job. . . ]

This command is only on systems that support job control. Puts each specified job into the background. The current job is put in the background if job is not specified. See Jobs for a description of the format of job.

§ break [n]

Exit from the enclosing for, while, until, or select loop, if any. If n is specified, then break n levels.

builtin [ -ds ] [ -f file] [name. . . ]

If name is not specified, and no -f option is specified, the built-ins are printed on standard output. The -s option prints only the special built-ins. Otherwise, each name represents the pathname whose basename is the name of the built-in. The entry point function name is determined by prepending b_ to the built-in name. Special built-ins cannot be bound to a pathname or deleted. The -d option deletes each of the given built-ins. On systems that support dynamic loading, the -f option names a shared library containing the code for built-ins. Once a library is loaded, its symbols become available for subsequent invocations of builtin. Multiple libraries can be specified with separate invocations of the builtin command. Libraries are searched in the reverse order in which they are specified. When a library is loaded, it looks for a function in the library whose name is lib_init() and invokes this function with an argument of 0.

cd [ -LP ] [arg]

cd [ -LP ] old new

This command can be in either of two forms. In the first form it changes the current directory to arg. If arg is - the directory is changed to the previous directory. The shell variable HOME is the default arg. The variable PWD is set to the current directory. The shell variable CDPATH defines the search path for the directory containing arg. Alternative directory names are separated by a colon (:). The default path is <null> (specifying the current directory). Note that the current directory is specified by a null path name, which can appear immediately after the equal sign or between the colon delimiters anywhere else in the path list. If arg begins with a / then the search path is not used. Otherwise, each directory in path is searched for arg. The second form of cd substitutes the string new for the string old in the current directory name, PWD, and tries to change to this new directory.

By default, symbolic link names are treated literally when finding the directory name. This is equivalent to the -L option. The -P option causes symbolic links to be resolved when determining the directory. The last instance of -L or -P on the command line determines which method is used. The cd command may not be executed by rsh.

command [ -pvV ] name [arg. . . ]

Without the -v or -V options, command executes name with the arguments given by arg. The -p option causes a default path to be searched rather than the one defined by the value of PATH. Functions will not be searched for when finding name. In addition, if name refers to a special built-in, none of the special properties associated with the leading daggers will be honored. (For example, the predefined alias redirect='command exec' prevents a script from terminating when an invalid redirection is given.) With the -v option, command is equivalent to the built-in whence command described below. The -V option causes command to act like whence -v.

§ continue [n]

Resume the next iteration of the enclosing for while until or select loop. If n is specified then resume at the nth enclosing loop.

disown [job. . . ]

Causes the shell not to send a HUP signal to each given job, or all active jobs if job is omitted, when a login shell terminates.

echo arg...

When the first arg does not begin with a -, and none of the arguments contain a \, then echo prints each of its arguments separated by a space and terminated by a new-line. Otherwise, the behavior of echo is system dependent and print or printf described below should be used. See echo(1) for usage and description.

§ eval [arg...]

The arguments are read as input to the shell and the resulting command(s) executed.

§ exec [arg...]

If arg is given, the command specified by the arguments is executed in place of this shell without creating a new process. The -c option causes the environment to be cleared before applying variable assignments associated with the exec invocation. The -a option causes name rather than the first arg, to become argv[0] for the new process. Input/output arguments may appear and affect the current process. If arg is not given, the effect of this command is to modify file descriptors as prescribed by the input/ output redirection list. In this case, any file descriptor numbers greater than 2 that are opened with this mechanism are closed when invoking another program.

§ exit [n]

Causes the shell to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted, then the exit status is that of the last command executed. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (see set below) turned on.

§§ export [-p] [name [=value] ] . . .

If name is not given, the names and values of each variable with the export attribute are printed with the values quoted in a manner that allows them to be reinput. The -p option causes the word export to be inserted before each one. Otherwise, the given names are marked for automatic export to the environment of subsequently-executed commands.

false

Does nothing, and exits 1. Used with until for infinite loops.

fg [job. . . ]

This command is only on systems that support job control. Each job specified is brought to the foreground and waited for in the specified order. Otherwise, the current job is brought into the foreground. See Jobs for a description of the format of job.

getconf [name [pathname] ]

Prints the current value of the configuration parameter given by name. The configuration parameters are defined by the IEEE POSIX 1003.1 and IEEE POSIX 1003.2 standards. (See pathconf(2) and sysconf(2).) The pathname argument is required for parameters whose value depends on the location in the file system. If no arguments are given, getconf prints the names and values of the current configuration parameters. The pathname / is used for each of the parameters that requires pathname.

getopts [ -a name] optstring vname [arg. . . ]

Checks arg for legal options. If arg is omitted, the positional parameters are used. An option argument begins with a + or a -. An option not beginning with + or - or the argument - - ends the options. optstring contains the letters that getopts recognizes. If a letter is followed by a :, that option is expected to have an argument. The options can be separated from the argument by blanks. The option -? causes getopts to generate a usage message on standard error. The -a argument can be used to specify the name to use for the usage message, which defaults to $0. getopts places the next option letter it finds inside variable vname each time it is invoked. The option letter will be prepended with a + when arg begins with a +. The index of the next arg is stored in OPTIND.

The option argument, if any, gets stored in OPTARG. A leading : in optstring causes getopts to store the letter of an invalid option in OPTARG, and to set vname to ? for an unknown option and to : when a required option is missing. Otherwise, getopts prints an error message. The exit status is non-zero when there are no more options. There is no way to specify any of the options :, +, -, ?, [, and ]. The option # can only be specified as the first option.

hist [ -e ename] [ -nlr ] [first [last] ]

hist -s [old=new] [command]

In the first form, a range of commands from first to last is selected from the last HISTSIZE commands that were typed at the terminal. The arguments first and last may be specified as a number or as a string. A string is used to locate the most recent command starting with the given string. A negative number is used as an offset to the current command number. If the -l option is selected, the commands are listed on standard output. Otherwise, the editor program ename is invoked on a file containing these keyboard commands. If ename is not supplied, then the value of the variable HISTEDIT is used. If HISTEDIT is not set, then FCEDIT (default /bin/ed) is used as the editor. When editing is complete, the edited command(s) is executed if the changes have been saved. If last is not specified, then it will be set to first. If first is not specified, the default is the previous command for editing and -16 for listing. The option -r reverses the order of the commands and the option -n suppresses command numbers when listing. In the second form, command is interpreted as first described above and defaults to the last command executed. The resulting command is executed after the optional substitution old =new is performed.

jobs [ -lnp ] [job. . . ]

Lists information about each given job; or all active jobs if job is omitted. The -l option lists process ids in addition to the normal information. The -n option only displays jobs that have stopped or exited since last notified. The -p option causes only the process group to be listed.

kill [ -s signame] job. . .

kill [ -n signum] job. . .

kill -l [sig. . . ]

Sends either the TERM (terminate) signal or the specified signal to the specified jobs or processes. Signals are either given by number with the -n option or by name with the -s option (as given in <signal.h>, stripped of the prefix "SIG" with the exception that SIGCLD is named CHLD). For backward compatibility, the n and s can be omitted and the number or name placed immediately after the -. If the signal being sent is TERM (terminate) or HUP (hangup), then the job or process will be sent a CONT (continue) signal if it is stopped. The argument job can be the process id of a process that is not a member of one of the active jobs. See Jobs for a description of the format of job. In the third form, kill -l, if sig is not specified, the signal names are listed. Otherwise, for each sig that is a name, the corresponding signal number is listed. For each sig that is a number, the signal name corresponding to the least significant 8 bits of sig is listed.

let arg...

Each arg is a separate arithmetic expression to be evaluated. See Arithmetic Evaluation earlier in this section, for a description of arithmetic expression evaluation. The exit status is 0 if the value of the last expression is non-zero, and 1 otherwise.

§ newgrp [arg. . . ]

Equivalent to exec /bin/newgrp arg. . . .

print [ -Rnprs ] [ -u unit] [ -f format] [arg. . . ]

With no options or with option - or - -, each arg is printed on standard output. The -f option causes the arguments to be printed as described by printf. In this case, any n, r, R options are ignored. Otherwise, unless the -R or -r, are specified, the following escape conventions will be applied: \a The alert character (ascii 07).

\b

The backspace character (ascii 010).

\c

Causes print to end without processing more arguments and not adding a new-line.

\f

The formfeed character (ascii 014).

\n

The new-line character (ascii 012).

\r

The carriage return character (ascii 015).

\t

The tab character (ascii 011).

\v

The vertical tab character (ascii 013).

\E

The escape character (ascii 033).

\\

The backslash character \.

\0x

The character defined by the 1, 2, or 3-digit octal string given by x.

The -R option will print all subsequent arguments and options other than -n. The -p option causes the arguments to be written onto the pipe of the process spawned with |& instead of standard output. The -s option causes the arguments to be written onto the history file instead of standard output. The -u option can be used to specify a one digit file descriptor unit number unit on which the output will be placed. The default is 1. If the option -n is used, no new-line is added to the output.

printf format [arg. . . ]

The arguments arg are printed on standard output in accordance with the ANSI-C formatting rules associated with the format string format. If the number of arguments exceeds the number of format specifications, the format string is reused to format remaining arguments. The following extensions can also be used:

  • A %b format can be used instead of %s to cause escape sequences in the corresponding arg to be expanded as described in print.

  • A %P format can be used instead of %s to cause arg to be interpreted as an extended regular expression and be printed as a shell pattern.

  • A %q format can be used instead of %s to cause the resulting string to be quoted in a manner than can be reinput to the shell.

  • The precision field of the %d format can be followed by a . and the output base.

pwd [ -LP ]

Outputs the value of the current working directory. The -L option is the default; it prints the logical name of the current directory. If the -P option is given, all symbolic links are resolved from the name. The last instance of -L or -P on the command line determines which method is used.

read [ -Aprs ] [ -d delim] [ -t timeout] [ -u unit] [vname?prompt] [vname. . . ]

The shell input mechanism. One line is read and is broken up into fields using the characters in IFS as separators. The escape character, \, is used to remove any special meaning for the next character and for line continuation. The -d option causes the read to continue to the first character of delim rather than new-line. In raw mode, -r, the \ character is not treated specially. The first field is assigned to the first vname, the second field to the second vname, etc., with leftover fields assigned to the last vname. The -A option causes the variable vname to be unset and each field that is read to be stored in successive elements of the indexed array vname. The -p option causes the input line to be taken from the input pipe of a process spawned by the shell using |&. If the -s option is present, the input will be saved as a command in the history file. The option -u can be used to specify a one digit file descriptor unit unit to read from. The file descriptor can be opened with the exec special built-in command. The default value of unit n is 0. The option -t is used to specify a timeout in seconds when reading from a terminal or pipe. If vname is omitted, then REPLY is used as the default vname. An end-of-file with the -p option causes cleanup for this process so that another can be spawned. If the first argument contains a ?, the remainder of this word is used as a prompt on standard error when the shell is interactive. The exit status is 0 unless an end-of-file is encountered or read has timed out.

§§ readonly [-p] [vname[=value] ] . . .

If vname is not given, the names and values of each variable with the readonly attribute are printed with the values quoted in a manner that allows them to be re-inputted. The -p option causes the word readonly to be inserted before each one. Otherwise, the given vnames are marked readonly and these names cannot be changed by subsequent assignment.

§ return [n]

Causes a shell function or . script to return to the invoking script with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted, then the return status is that of the last command executed. If return is invoked while not in a function or a . script, then it behaves the same as exit.

§ set [±Cabefhkmnopstuvx] [±o [option] ] . . . [±A vname] [arg. . . ]

The options for this command have meaning as follows:

-A

Array assignment. Unset the variable vname and assign values sequentially from the arg list. If +A is used, the variable vname is not unset first.

-C

Prevents redirection > from truncating existing files. Files that are created are opened with the O_EXCL mode. Requires >| to truncate a file when turned on.

-a

All subsequent variables that are defined are automatically exported.

-b

Prints job completion messages as soon as a background job changes state rather than waiting for the next prompt.

-e

If a command has a non-zero exit status, execute the ERR trap, if set, and exit. This mode is disabled while reading profiles.

-f

Disables file name generation.

-h

Each command becomes a tracked alias when first encountered.

-k

(Obsolete). All variable assignment arguments are placed in the environment for a command, not just those that precede the command name.

-m

Background jobs will run in a separate process group and a line will print upon completion. The exit status of background jobs is reported in a completion message. On systems with job control, this option is turned on automatically for interactive shells.

-n

Read commands and check them for syntax errors, but do not execute them. Ignored for interactive shells.

-o

The following argument can be one of the following option names:

allexport

Same as -a.

errexit

Same as -e.

bgnice

All background jobs are run at a lower priority. This is the default mode.

emacs

Puts you in an emacs style in-line editor for command entry.

gmacs

Puts you in a gmacs style in-line editor for command entry.

ignoreeof

The shell will not exit on end-of-file. The command exit must be used.

keyword

Same as -k.

markdirs

All directory names resulting from file name generation have a trailing / appended.

monitor

Same as -m.

noclobber

Same as -C.

noexec

Same as -n.

noglob

Same as -f.

nolog

Do not save function definitions in the history file.

notify

Same as -b.

nounset

Same as -u.

privileged

Same as -p.

verbose

Same as -v.

trackall

Same as -h.

vi

Puts you in insert mode of a vi style inline editor until you hit the escape character 033. This puts you in control mode. A return sends the line.

viraw

Each character is processed as it is typed in vi mode.

xtrace

Same as -x.

If no option name is supplied, then the current option settings are printed.

-p

Disables processing of the $HOME/.profile file and uses the file /etc/suid_profile instead of the ENV file. This mode is on whenever the effective uid (gid) is not equal to the real uid (gid). Turning this off causes the effective uid and gid to be set to the real uid and gid.

-s

Sort the positional parameters lexicographically.

-t

(Obsolete). Exit after reading and executing one command.

-u

Treat unset parameters as an error when substituting.

-v

Print shell input lines as they are read.

-x

Print commands and their arguments as they are executed.

- -

Do not change any of the options; useful in setting $1 to a value beginning with -. If no arguments follow this option then the positional parameters are unset.

As an obsolete feature, if the first arg is - then the -x and -v options are turned off and the next arg is treated as the first argument. Using + rather than - causes these options to be turned off. These options can also be used upon invocation of the shell. The current set of options may be found in $-. Unless -A is specified, the remaining arguments are positional parameters and are assigned, in order, to $1 $2. . . . If no arguments are given, then the names and values of all variables are printed on the standard output.

§shift [n]

The positional parameters from $n+1. . . are renamed $1. . . , default n is 1. The parameter n can be any arithmetic expression that evaluates to a non-negative number less than or equal to $#.

sleep seconds

Suspends execution for the number of decimal seconds or fractions of a second given by seconds.

§ trap [-p] [action] [sig] . . .

The -p option causes the trap action associated with each trap as specified by the arguments to be printed with appropriate quoting. Otherwise, action will be processed as if it were an argument to eval when the shell receives signal(s) sig. Each sig can be given as a number or as the name of the signal. Trap commands are executed in order of signal number. Any attempt to set a trap on a signal that was ignored on entry to the current shell is ineffective. If action is omitted and the first sig is a number, or if action is -, then the trap(s) for each sig are reset to their original values. If action is the null string then this signal is ignored by the shell and by the commands it invokes. If sig is ERR then action will be executed whenever a command has a non-zero exit status. If sig is DEBUG then action will be executed before each command. If sig is 0 or EXIT and the trap statement is executed inside the body of a function, then the command action is executed after the function completes. If sig is 0 or EXIT for a trap set outside any function then the command action is executed on exit from the shell. If sig is KEYBD, then action will be executed whenever a key is read while in emacs, gmacs, or vi mode. The trap command with no arguments prints a list of commands associated with each signal number.

true

Does nothing, and exits 0. Used with while for infinite loops.

§§ typeset [±AHflnprtux] [±EFLRZi [n] ] [vname [=value] ] . . .

Sets attributes and values for shell variables and functions. When invoked inside a function, a new instance of the variable vname is created. The variable's value and type are restored when the function completes. The following list of attributes may be specified:

-A

Declares vname to be an associative array. Subscripts are strings rather than arithmetic expressions.

-E

Declares vname to be a double precision floating point number. If n is non-zero, it defines the number of significant figures that are used when expanding vname. Otherwise, ten significant figures will be used.

-F

Declares vname to be a double precision floating point number. If n is non-zero, it defines the number of places after the decimal point that are used when expanding vname. Otherwise ten places after the decimal point will be used.

-H

This option provides Unix to host-name file mapping on non-Unix machines.

-L

Left justify and remove leading blanks from value. If n is non-zero, it defines the width of the field, otherwise it is determined by the width of the value of first assignment. When the variable is assigned to, it is filled on the right with blanks or truncated, if necessary, to fit into the field. The -R option is turned off.

-R

Right justify and fill with leading blanks. If n is non-zero, it defines the width of the field, otherwise it is determined by the width of the value of first assignment. The field is left filled with blanks or truncated from the end if the variable is reassigned. The -L option is turned off.

-Z

Right justify and fill with leading zeros if the first non-blank character is a digit and the -L option has not been set. Remove leading zeros if the -L option is also set. If n is non-zero, it defines the width of the field, otherwise it is determined by the width of the value of first assignment.

-f

The names refer to function names rather than variable names. No assignments can be made and the only other valid options are -t, -u and -x. The -t option turns on execution tracing for this function. The -u option causes this function to be marked undefined. The FPATH variable will be searched to find the function definition when the function is referenced.

-i

Declares vname to be represented internally as integer. The right hand side of an assignment is evaluated as an arithmetic expression when assigning to an integer. If n is non-zero, it defines the output arithmetic base, otherwise the output base will be ten.

-l

All upper-case characters are converted to lower-case. The upper-case option, -u, is turned off.

-n

Declares vname to be a reference to the variable whose name is defined by the value of variable vname. This is usually used to reference a variable inside a function whose name has been passed as an argument.

-r

The given vnames are marked readonly and these names cannot be changed by subsequent assignment.

-t

Tags the variables. Tags are user definable and have no special meaning to the shell.

-u

All lower-case characters are converted to upper-case. The lower-case option, -l, is turned off.

-x

The given vnames are marked for automatic export to the environment of subsequently-executed commands. Variables whose names contain a . cannot be exported.

The -i attribute cannot be specified along with -R, -L, -Z, or -f.

Using + rather than - causes these options to be turned off. If no vname arguments are given, a list of vnames (and optionally the values) of the variables is printed. (Using + rather than - keeps the values from being printed.) The -p option causes typeset followed by the option letters to be printed before each name rather than the names of the options. If any option other than -p is given, only those variables which have all of the given options are printed. Otherwise, the vnames and attributes of all variables are printed.

ulimit [ -HSacdfmnpstv ] [limit]

Set or display a resource limit. The available resource limits are listed below. Many systems do not support one or more of these limits. The limit for a specified resource is set when limit is specified. The value of limit can be a number in the unit specified below with each resource, or the value unlimited. The -H and -S options specify whether the hard limit or the soft limit for the given resource is set. A hard limit cannot be increased once it is set. A soft limit can be increased up to the value of the hard limit. If neither the H nor S options is specified, the limit applies to both. The current resource limit is printed when limit is omitted. In this case, the soft limit is printed unless H is specified. When more than one resource is specified, then the limit name and unit is printed before the value.

-a

Lists all of the current resource limits.

-c

The number of 512-byte blocks on the size of core dumps.

-d

The number of K-bytes on the size of the data area.

-f

The number of 512-byte blocks on files that can be written by the current process or by child processes (files of any size may be read).

-m

The number of K-bytes on the size of physical memory.

-n

The number of file descriptors plus 1.

-p

The number of 512-byte blocks for pipe buffering.

-s

The number of K-bytes on the size of the stack area.

-t

The number of CPU seconds to be used by each process.

-v

The number of K-bytes for virtual memory.

If no option is given, -f is assumed.

umask [ -S ] [mask]

The user file-creation mask is set to mask (see umask(2)). mask can either be an octal number or a symbolic value as described in chmod(1). If a symbolic value is given, the new umask value is the complement of the result of applying mask to the complement of the previous umask value. If mask is omitted, the current value of the mask is printed. The -S option causes the mode to be printed as a symbolic value. Otherwise, the mask is printed in octal.

§ unalias [-a] name. . .

The aliases given by the list of names are removed from the alias list. The -a option causes all the aliases to be unset.

§unset [-fnv] vname. . .

The variables given by the list of vnames are unassigned, i.e., their values and attributes are erased. Readonly variables cannot be unset. If the -f option is set, then the names refer to function names. If the -v option is set, then the names refer to variable names. The -f option overrides -v. If -n is set and name is a name reference, then name will be unset rather than the variable that it references. The default is equivalent to -v. Unsetting LINENO, MAILCHECK, OPTARG, OPTIND, RANDOM, SECONDS, TMOUT, and _ removes their special meaning even if they are subsequently assigned to.

wait [job. . . ]

Wait for the specified job and report its termination status. If job is not given, then all currently active child processes are waited for. The exit status from this command is that of the last process waited for. See Jobs for a description of the format of job.

whence [ -afpv ] name. . .

For each name, indicate how it would be interpreted if used as a command name. The -v option produces a more verbose report. The -f options skips the search for functions. The -p option does a path search for name even if name is an alias, a function, or a reserved word. The -a option is similar to the -v option but causes all interpretations of the given name to be reported.


       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net