Text-only Table of Contents (frame/ no frame)
(21) Miscellaneous Previous Top Next

Miscellaneous internal commands

The shells (ksh in particular) have many more internal commands. Some are used more in interactive shells. The commands listed here are used in scripts, but don't conveniently fit elsewhere in the class.
eval args
The args are read as input to the shell and the resulting command executed. Allows "double" expansion of some constructs. For example, constructing a variable name out of pieces, and then obtaining the value of that variable.

netdev=NETDEV_ 
NETDEV_1=hme0         # As part of an initialization step defining multiple devices

devnum=1              # As part of a loop over those devices
ifname=$netdev$devnum # construct a variable name NETDEV_1
eval device=\$$ifname # evaluate it - device is set to hme0
exec command args
The command is executed in place of the current shell. There is no return from an exec. I/O redirection may be used. This is also used to change the I/O for the current shell.
:
The line is variable-expanded, but otherwise treated as a comment. Sometimes used as a synonym for "true" in a loop.
while :; do
  # this loop will go forever until broken by 
  # a conditional test inside, or a signal
done

unset var ...
Remove the named variables. This is not the same as setting their values to null.

typeset [+/- options] [ name[=value] ] ... (ksh only, bash uses declare for similar functions)
Set attributes and values for shell variables and functions. When used inside a function, a local variable is created. Some of the options are:
-L[n]
Left justify and remove leading blanks. The variable always has length n if specified.
-R[n]
Right justify and fill with leading blanks. The variable always has length n if specified.
-l
The named variable is always treated as an integer. This makes arithmetic faster. The reserved word integer is an alias for typeset -i.
Less detail
-Z[n]
As for -R, but fill with zeroes if the value is a number
-i
Lower-case convert the named variables
-u
Upper-case convert the named variables
-r
Mark the variables as readonly
-x
Export the named variables to the enviroment
-ft
The variables are taken as function names. Turn on execution tracing.

Previous Top Next


misc-internal.src  last modified Sep 14, 2005 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College