Previous Section  < Day Day Up >  Next Section

10.11. Built-In Commands

Rather than residing on disk like UNIX/Linux commands, built-in commands are part of the C/TC shell's internal code and are executed from within the shell. If a built-in command occurs as any component of a pipeline except the last, it is executed in a subshell. See Table 10.11 for a list of built-in commands that apply to both the C and TC shells. For an extended list of TC shell only built-in commands, see Table 9.25 on page 504.

Table 10.11. C and TC Shell Built-In Commands and Their Meanings

Command

Meaning

:

Interprets null command, but performs no action.

alias

A nickname for a command.

bg [%job]

Runs the current or specified jobs in the background.

break

Breaks out of the innermost foreach or while loop.

breaksw

Breaks from a switch, resuming after the endsw.

case label:

A label in a switch statement.


cd [dir]

chdir [dir]


Changes the shell's working directory to dir. If no argument is given, change to the home directory of the user.

continue

Continues execution of the nearest enclosing while or foreach.

default:

Labels the default case in a switch statement. The default should come after all case labels.

dirs [–l]

Prints the directory stack, most recent to the left; the first directory shown is the current directory. With the –l argument, produces an unabbreviated printout; use of the ~ notation is suppressed.

echo [–n] list

Writes the words in list to the shell's standard output, separated by space characters. The output is terminated with a newline unless the –n option is used.

eval command

Runs command as standard input to the shell and executes the resulting commands. This is usually used to execute commands generated as the result of command or variable substitution, as parsing occurs before these substitutions (e.g., eval 'tset -s options').

exec command

Executes command in place of the current shell, which terminates.

exit [(expr)]

Exits the shell, either with the value of the status variable or with the value specified by expr.

fg [% job]

Brings the current or specified job into the foreground.

foreach var (wordlist)

See "The foreach Loop" on page 561.

glob wordlist

Performs filename expansion on wordlist. Like echo, but no escapes (\) are recognized. Words are delimited by null characters in the output.

goto label

See "The goto" on page 547.

hashstat

Prints a statistics line indicating how effective the internal hash table has been at locating commands (and avoiding execs). An exec is attempted for each component of the path where the hash function indicates a possible hit, and in each component that does not begin with a backslash.

history [–hr] [n]

Displays the history list; if n is given, display only the n most recent events.

–r

Reverses the order of the printout to be most recent first rather than oldest first.

–h

Displays the history list without leading numbers. This is used to produce files suitable for sourcing using the –h option to source.

if (expr)

See "Conditional Constructs and Flow Control" on page 535.

else if (expr2) then

See "Conditional Constructs and Flow Control" on page 535.

jobs [–l]

Lists the active jobs under job control.

–l

–Lists IDs in addition to the normal information.


kill [–sig] [pid][%job] ...

kill –l


Sends the TERM (terminate) signal, by default or by the signal specified, to the specified ID, the job indicated, or the current job. Signals are given either by number or name. There is no default. Typing kill does not send a signal to the current job. If the signal being sent is TERM (terminate) or HUP (hangup), then the job or process is sent a CONT (continue) signal as well.

–l

List the signal names that can be sent.

limit [–h] [resource [max–use]]

Limit the consumption by the current process or any process it spawns, each not to exceed max–use on the specified resource. If max–use is omitted, print the current limit; if resource is omitted, display all limits.

–h

Uses hard limits instead of the current limits. Hard limits impose a ceiling on the values of the current limits. Only the superuser may raise the hard limits. Resource is one of: cputime, maximum CPU seconds per process; filesize, largest single file allowed; datasize, maximum data size (including stack) for the process; stacksize, maximum stack size for the process; coredump, maximum size of a core dump; and descriptors, maximum value for a file descriptor.

login [username|–p]

Terminates a login shell and invokes login(1). The .logout file is not processed. If username is omitted, login prompts for the name of a user.

–p

Preserves the current environment (variables).

logout

Terminates a login shell.

nice [+n|–n] [command]

Increments the process priority value for the shell or command by n. The higher the priority value, the lower the priority of a process and the slower it runs. If command is omitted, nice increments the value for the current shell. If no increment is specified, nice sets the nice value to 4. The range of nice values is from –20 through 19. Values of n outside this range set the value to the lower or higher boundary, respectively.

+n

Increments the process priority value by n.

–n

Decrements by n. This argument can be used only by the superuser.

nohup [command]

Runs command with HUPs (hangups) ignored. With no arguments, ignores HUPs throughout the remainder of a script.

notify [%job]

Notifies the user asynchronously when the status of the current or of a specified job changes.

onintr [– | label]

Controls the action of the shell on interrupts. With no arguments, onintr restores the default action of the shell on interrupts. (The shell terminates shell scripts and returns to the terminal command input level.) With the minus sign argument, the shell ignores all interrupts. With a label argument, the shell executes a goto label when an interrupt is received or a child process terminates because it was interrupted.

popd [+n]

Pops the directory stack and cd to the new top directory. The elements of the directory stack are numbered from zero, starting at the top.

 

+n

Discard the nth entry in the stack.

pushd [+n | dir]

Pushes a directory onto the directory stack. With no arguments, exchange the top two elements.

 

+n

Rotates the nth entry to the top of the stack and cd to it.

 

dir

Pushes the current working directory onto the stack and change to dir.

rehash

Recomputes the internal hash table of the contents of directories listed in the path variable to account for new commands added.

repeat count command

Repeat command count times.

set [var [= value]]

See "Variables" on page 440.

setenv [VAR [word]]

See "Variables" on page 440. The most commonly used environment variables, USER, TERM, and PATH, are automatically imported to and exported from the csh variables, user, term, and path; there is no need to use setenv for these. In addition, the shell sets the PWD environment variable from the csh variable cwd whenever the latter changes.

shift [variable]

The components of argv, or variable, if supplied, are shifted to the left, discarding the first component. It is an error for variable not to be set, or to have a null value.

source [–h] name

Reads commands from name. Source commands may be nested, but if they are nested too deeply, the shell may run out of file descriptors. An error in a sourced file at any level terminates all nested source commands. Used commonly to re-execute the .login or .cshrc files to ensure variable settings are handled within the current shell, that is, to make sure the shell does not create (fork) a child shell.

 

–h

Places commands from the filename on the history list without executing them.

stop [%job] ...

Stops the current or specified background job.

suspend

Stops the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su.

switch (string)

See "The switch Command" on page 557.

time [command]

With no argument, print a summary of time used by this shell and its children. With an optional command, execute command and print a summary of the time it uses.

umask [value]

Displays the file creation mask. With value, sets the file creation mask. Value, given in octal, is XORed with the permissions of 666 for files and 777 for directories to arrive at the permissions for new files. Permissions cannot be added via umask.

unalias pattern

Discards aliases that match (filename substitution) pattern. All aliases are removed by unalias *.

unhash

Disables the internal hash table.

unlimit [–h] [resource]

Removes a limitation on resource. If no resource is specified, all resource limitations are removed. See the description of the limit command for the list of resource names.

 

–h

Removes corresponding hard limits. Only the superuser may do this.

unset pattern

Removes variables whose names match (filename substitution) pattern. All variables are removed by unset *; this has noticeably distasteful side effects.

unsetenv variable

Removes variable from the environment. Pattern matching, as with unset, is not performed.

wait

Waits for background jobs to finish (or for an interrupt) before prompting.

while (expr)

See "The while Loop" on page 564.


    Previous Section  < Day Day Up >  Next Section