.\" extracted from rc.sh by cmt2doc.pl
.TH RC 8 "6 February 1999" "FreeWare" "MAINTENANCE COMMANDS"
.PD .8v
.SH NAME

rc\&.sh \- run commands

.SH SYNOPSIS
.nf
\fBrc\&.sh\fR [\fB\-v\fR] [\fB\-n\fR] [\fB\-e\fR] [\fB\-d\fR \fIdir\fR] [\fB\-c\fR \fIclass\fR] [\fIargs\fR]
.fi

.SH DESCRIPTION

This is a generic rc script inspired by rc2 et al from SysV.

This script looks for all files that start with \fIclass\fR
in the directory \fIdir\fR (default is the script name without
\fB\&.sh\fR and with \fB\&.d\fR appended) and executes them. 

If the file name ends in \fB\&.sh\fR it is sourced into the
current process, otherwise it is run as a child process with
\fIargs\fR as argument.  The treatment of \fB\&.sh\fR files provides a
mechanism for controlling behaviour of subsequent modules as
well as \fBrc\&.sh\fR itself.

When running a child process \fB\&.pl\fR files are fed to perl(1) or
whatever the \fIPERL\fR variable names, and everything else is fed
to the shell.

If \fIclass\fR is \fBS\fR then the default \fIargs\fR is \fBstart\fR.

If \fIclass\fR is \fBK\fR then the default \fIargs\fR is \fBstop\fR.

If \fIargs\fR contains any ``:'' characters then each word in
\fIargs\fR is assumed to be a \fIdir\fR:\fIclass\fR:\fIarg\fR tupple.

If neither \fIclass\fR nor \fIargs\fR are specified then the default
behaviour is as if \fIargs\fR were ``\fIdir\fR:K:stop \fIdir\fR:S:start''
which provides a reasonable imitation of rc\fIN\fR and is
generally quite useful.
.TP
Options:
.TP
\fB\-e\fR
Stop on error. Unlike its namesake in sh(1) we do not
exit if any command in any script fails, rather we
exit if one of the scripts (sourced or run) returns a
non-zero status. Note, setting ErrExit=exit in a \&.sh
file has the same effect.
.TP
\fB\-v\fR
Echo each script name as it is processed.
.TP
\fB\-n\fR
Do nothing, just show what would be done.
.TP
\fB\-d\fR \fIdir\fR
Process files in \fIdir\fR.
.TP
\fB\-c\fR \fIclass\fR
Process files in \fIdir\fR that start with \fIclass\fR.
.TP
Functions:
.PP
The following functions form part of the \fBrc\&.sh\fR
implementation and are available for use from other \fB\&.sh\fR
files.
.TP
RunCommands \fIdir\fR [\fIclass\fR [\fIarg\fR] \&...]
This function is actually the guts of \fBrc\&.sh\fR.
Sets \fIMydir\fR to \fIdir\fR so that modules in \fIdir\fR don't
need to work it out.
.TP
RunSubs \fIdir\fR \&...
Assumes \fIMydir\fR is set, and will look for a directory
of the same name under each \fIdir\fR.  If there is a
command in \fIdir\fR that corresponds to the directory
(eg. \fIMydir\fR=/configs/config\&.d, \fIdir\fR=/configs/NetBSD,
we look for /configs/NetBSD/config\&.d and if it exists
we check for /configs/NetBSD/config or
/configs/NetBSD/config\&.sh to process
/configs/NetBSD/config\&.d). If no such command is
found, we call RunCommands.
.PP

.SH BUGS
.PP
This script would have been called \fBrc\fR except that would have
caused too many support problems.  Calling it \fBrc\&.sh\fR allows
it to coexist with the normal operating system facilities.

We avoid use of anything but shell internals so that we can
run while the system is in single user mode and few
filesystems are mounted.  Because we do not use getopt(1), we
require a space between each option and between options and
their args.

It would be nice if we could check for a file being executable
other than by attempting to run it as this would provide
support for interpreters other than sh and perl as well as
direct execution of compiled binaries. Sadly, on most older
systems test \-x does not do the right thing in the presence of
symlinks.  If you want this feature and your test is not
broken, define TEST_X_OK.

.SH AUTHOR

Simon J. Gerraty <sjg@quick\&.com\&.au>

