rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 2c998c165268f24f038e02f103e07a967b343c3f
parent f983e502ce8fc8d1d0289b8feb269218a70618e6
Author: Toby Goodwin <tjg@star.le.ac.uk>
Date:   Wed, 12 May 1999 16:47:55 +0100

beta: rc-1.5b6

Diffstat:
MAUTHORS | 12++++++------
MChangeLog | 35+++++++++++++++++++++++++++++++++++
MEXAMPLES | 16++++++++--------
MREADME | 2+-
Macinclude.m4 | 21+++++++++++++++++++--
Mconfigure.ac | 20++++++++++----------
Mrc.1 | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Msignal.c | 2++
8 files changed, 147 insertions(+), 39 deletions(-)

diff --git a/AUTHORS b/AUTHORS @@ -27,9 +27,9 @@ mind that it describes a program that was written at AT&T and that the version of rc presented here differs in some respects. Tim would like to thank these people for their contributions since he -took over maintenance of rc. Arvid Requate, Bengt Kleberg, Brynjulv -Hauksson, Byron Rakitzis, Chris Siebenmann, David Swasey, Gerry -Tomlinson, Gert-Jan Vons, Ian Lance Taylor, Jeremy Fitzhardinge, Marc -Moorcroft, Mark K Gardner, Raymond Venneker, Rich $alz, Rob Savoye, -Scott Schwartz, Stefan Dalibor, Tom Culliton, Tom Tromey, Vincent -Broman. +took over maintenance of rc. Aharon Robbins, Arvid Requate, Bengt +Kleberg, Brynjulv Hauksson, Byron Rakitzis, Chris Siebenmann, David +Swasey, Gerry Tomlinson, Gert-Jan Vons, Ian Lance Taylor, Jeremy +Fitzhardinge, Marc Moorcroft, Mark K Gardner, Raymond Venneker, Rich +$alz, Rob Savoye, Scott Schwartz, Stefan Dalibor, Tom Culliton, Tom +Tromey, Vincent Broman, Wolfgang Zekoll. diff --git a/ChangeLog b/ChangeLog @@ -554,3 +554,38 @@ Changes since rc-1.5b2 improvements. Release: rc-1.5b5. + +1999-02-15 + + Portability: AM_INIT_AUTOMAKE calls AC_ARG_PROGRAM and + AC_PROG_INSTALL. Don't do it explicitly. For once, the configure + script gets smaller! Program name transformations work right now. + + Documentation: note that rc has no `set' builtin; fix weird variable + name example; any character except `=' may be used in a variable name; + document bqstatus; document rc's exit status; other tidying. + +1999-03-01 + + Documentation: document the yacc-imposed limit on ; separated commands + in a line. + +1999-05-06 + + Portability: tgetent() might be in -lncurses instead of -ltermcap. + +1999-05-10 + + Portability: Linux *almost* has SysV SIGCLD semantics, and we need to + detect them. + + Bug: if we reset SIGCLD to SIG_DFL, we need to record the fact in the + sighandlers[] array. + +1999-05-12 + + Documentation: note that `$(a.b)' syntax only mostly works, and that + list definitions in exported functions are noisier than they need to + be. + + Release: rc-1.5b6. diff --git a/EXAMPLES b/EXAMPLES @@ -1,6 +1,6 @@ -There is no repository for useful rc code snippets as yet, so I'm including -a (short) file in the distribution with some helpful/intriguing pieces of -rc code. +There is no repository for useful rc code snippets as yet, so +I'm including a (short) file in the distribution with some +helpful/intriguing pieces of rc code. A sample .rcrc -------------- @@ -624,7 +624,7 @@ Status: RO Use trimhist [-#lines] -trims your history file back; useful for folks with dis quota's :-) +trims your history file back; useful for folks with disk quota's :-) fn trimhist { p1=-100 { cp $history $history^'~' ~ $#* 1 && p1=$1 @@ -742,8 +742,8 @@ fn pathprefix { p1=() i=() j=() { home=/user/users/rsalz z=/usr/users -pathprefix /usr/users/rsalz home usr # --> $home -pathprefix /usr/users/rsalz z # --> $z/rsalz -pathprefix /usr/users/rsalz/foo z home # --> $z/rsalz/foo -pathprefix /usr/users/rsalz/foo home # --> $home/foo +pathprefix /usr/users/rsalz home usr # --> $home +pathprefix /usr/users/rsalz z # --> $z/rsalz +pathprefix /usr/users/rsalz/foo z home # --> $z/rsalz/foo +pathprefix /usr/users/rsalz/foo home # --> $home/foo diff --git a/README b/README @@ -1,4 +1,4 @@ -This is a beta release, rc-1.5b5. +This is a beta release, rc-1.5b6. See COPYING for copying information. All files are diff --git a/acinclude.m4 b/acinclude.m4 @@ -145,7 +145,12 @@ sigaction(SIGINT, 0, 0); dnl Do we have SysV SIGCLD semantics? In other words, if we set the -dnl action for SIGCLD to SIG_IGN does wait() always say ECHILD? +dnl action for SIGCLD to SIG_IGN does wait() always say ECHILD? Linux, +dnl of course, is bizarre here. It basically implements the SysV +dnl semantics, but if the parent calls wait() before the child calls +dnl exit(), wait() returns with the PID of the child as normal. (Real +dnl SysV waits for all children to exit, then returns with ECHILD.) +dnl Anyway, this is why the `sleep(1)' is there. AC_DEFUN(RC_SYS_V_SIGCLD, [ AC_CACHE_CHECK(for SysV SIGCLD semantics, rc_cv_sysv_sigcld, AC_TRY_RUN([ @@ -156,13 +161,14 @@ AC_DEFUN(RC_SYS_V_SIGCLD, [ #include <unistd.h> int main(void) { int i; - sigset(SIGCLD, SIG_IGN); + signal(SIGCLD, SIG_IGN); switch (fork()) { case -1: return 1; case 0: return 0; default: + sleep(1); if (wait(&i) == -1 && errno == ECHILD) return 0; else return 1; } @@ -204,3 +210,14 @@ main() { yes) AC_DEFINE(HAVE_FIFO) ;; esac ]) + +dnl Where is tgetent()? +AC_DEFUN(RC_LIB_TGETENT, [ + AC_CHECK_LIB(termcap, tgetent, + rc_lib_tgetent=-ltermcap, + AC_CHECK_LIB(ncurses, tgetent, + rc_lib_tgetent=-lncurses, + AC_MSG_ERROR(tgetent not found) + ) + ) +]) diff --git a/configure.ac b/configure.ac @@ -8,13 +8,10 @@ dnl Automake stuff. dnl Use this one for snapshots... dnl AM_INIT_AUTOMAKE(rc, 1.5s`echo $RELDATE |sed 's/-//g'`) dnl ...and this one for releases -AM_INIT_AUTOMAKE(rc, 1.5b5) +AM_INIT_AUTOMAKE(rc, 1.5b6) AM_CONFIG_HEADER(config.h) -dnl Anybody using name transformations? -AC_ARG_PROGRAM - dnl Find a standard C compiler AC_PROG_CC AM_PROG_CC_STDC @@ -28,7 +25,6 @@ yes) CFLAGS="-Wall $CFLAGS" ;; esac AC_PROG_CPP -AC_PROG_INSTALL AC_CHECK_PROGS(LN, ln cp) AC_CHECK_HEADERS(sys/resource.h sys/time.h sys/types.h unistd.h) @@ -178,19 +174,23 @@ AC_ARG_WITH(editline, [ --with-editline Simmule Turner's line editing], AC_DEFINE(EDITLINE) LIBS="$LIBS -ledit", AC_MSG_ERROR(editline library not found))) +if test "${with_vrl+set}" = set -o "${with_readline+set}" = set; then + RC_LIB_TGETENT +fi + AC_ARG_WITH(vrl, [ --with-vrl Gert-Jan Vons's line editing], AC_CHECK_LIB(vrl, readline, - AC_DEFINE(EDITLINE) LIBS="$LIBS -lvrl -ltermcap", - AC_MSG_ERROR(vrl library not found), -ltermcap)) + AC_DEFINE(EDITLINE) LIBS="$LIBS -lvrl $rc_lib_tgetent", + AC_MSG_ERROR(vrl library not found), $rc_lib_tgetent)) dnl There are (at least) two incompatible versions of readline, and we dnl need to know which one we are using. We don't support readline 2.0. AC_ARG_WITH(readline, [ --with-readline Bloated GNU line editing], [ AC_CHECK_LIB(readline, readline, [ AC_DEFINE(READLINE) - LIBS="$LIBS -lreadline -ltermcap" - AC_CHECK_LIB(readline, _rl_clean_up_for_exit, , AC_DEFINE(READLINE_OLD), -ltermcap) - ], AC_MSG_ERROR(readline library not found), -ltermcap) + LIBS="$LIBS -lreadline $rc_lib_tgetent" + AC_CHECK_LIB(readline, _rl_clean_up_for_exit, , AC_DEFINE(READLINE_OLD), $rc_lib_tgetent) + ], AC_MSG_ERROR(readline library not found), $rc_lib_tgetent) ]) AM_CONDITIONAL(AMC_READLINE, test "${with_readline+set}" = set) diff --git a/rc.1 b/rc.1 @@ -161,7 +161,7 @@ .if !"\\$4"" .Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9" .if "\\$4"" \\$3\fR\s10 .. -.TH RC 1 "28 April 1991" +.TH RC 1 "1999-05-12" .SH NAME rc \- shell .SH SYNOPSIS @@ -298,7 +298,7 @@ run setuid .I rc scripts; the usual caveats about the setuid bit still apply.) .TP -.Cr \- s +.Cr \-s This flag causes .I rc to read from standard input. Any arguments are @@ -601,7 +601,7 @@ and the output version of this notation: .SH "CONTROL STRUCTURES" The following may be used for control flow in .IR rc : -.SS "If-else Statements" +.SS "If-Else Statements" .PD 0 .sp .Ci "if (" test ") {" @@ -820,7 +820,7 @@ and .Cr "?" . However, .I rc -does expand the glob the subject against filenames if it contains +does expand the subject against filenames if it contains metacharacters. Thus, the command .Ds @@ -945,8 +945,18 @@ A list may be assigned to a variable, using the notation: .Ic var " = " list .De .PP -Any sequence of non-special characters, except a sequence including -only digits, may be used as a variable name. +The special variable +.Cr * +may be assigned to using this notation; +.I rc +has no +.B set +builtin. +.PP +Any non-empty sequence of characters, except a sequence including only +digits, may be used as a variable name. Any character except +.Cr = +may be used, but special characters must be quoted. All user-defined variables are exported into the environment. .PP The value of a variable is referenced with the notation: @@ -989,7 +999,7 @@ To reference a variable with other characters in its name, quote the variable name. Thus: .Ds -.Cr "echo $'we$Ird\Variab!le'" +.Cr "echo $'we$Ird:Variab!le'" .De .SS "Local Variables" Any number of variable assignments may be made local to a single @@ -1180,6 +1190,11 @@ The process ID of the last process started in the background. The process IDs of any background processes which are outstanding or which have died and have not been waited for yet. .TP +.Cr bqstatus +The exit status of the +.I rc +forked to execute the most recent backquote substitution. +.TP .Cr cdpath A list of directories to search for the target of a .B cd @@ -1654,7 +1669,7 @@ waits for all child processes to exit. \fBwhatis \fR[\fB\-b\fR] \fR[\fB\-f\fR] \fR[\fB\-p\fR] \fR[\fB\-s\fR] \fR[\fB\-v\fR] [\fB\-\|\-\fR] [\fIname ...\fR] Prints a definition of the named objects. For builtins, -.B builtin +.Cr builtin .I foo is printed; for functions, including signal handlers, their definitions are printed; for executable files, path names are printed; and for @@ -1665,11 +1680,11 @@ programs, signal handlers, and variables, respectively. If no are specified, .I rc lists all objects of that type. (This is not permitted for -.BR -p .) +.Cr \-p .) Without arguments, -.B whatis +.Cr whatis is equivalent to -.BR "whatis -fv" , +.Cr "whatis -fv" , and prints the values of all shell variables and functions. .TP \& @@ -1710,6 +1725,24 @@ For example, .Ds .Cr "whatis \-\|\- \-p" .De +.SH "EXIT STATUS" +The exit status of +.I rc +is normally the same as that of the +last command executed. If the last +command was a pipeline, +.I rc +exits +.Cr 0 +if every command in the pipeline did; +otherwise it exits +.Cr 1 . +.PP +.I rc +can be made to exit with a particular +status using the +.B exit +builtin. .SH GRAMMAR Here is .IR rc 's @@ -1816,7 +1849,7 @@ optnl: /* empty */ | optnl '\en' .I rc was written by Byron Rakitzis, with valuable help from Paul Haahr, Hugh Redelmeier and David Sanderson. -The design of this shell has been copied from the +The design of this shell was copied from the .I rc that Tom Duff wrote at Bell Labs. .SH BUGS @@ -1826,6 +1859,14 @@ descendant .IR rc processes. .PP +There is a compile-time limit on the number of +.Cr ; +separated commands in a line: usually 500. +This is sometimes a problem for automatically generated scripts: +substituting the newline character for +.Cr ; +avoids the limit. +.PP On modern systems that support .Cr /dev/fd or @@ -1857,6 +1898,19 @@ The notation for flattening should allow for using an arbitrary separating character, not just space. .PP +It is usually possible to use parentheses to defeat +free caret insertion; that is, to use +.Cr $(x.y) +as a synonym for +.Cr $'x.y' . +However, the former syntax is not correctly handled in functions +exported to the environment: a function defined using this syntax will +not work properly in descendant +.I rc +processes. +.PP +List definitions in exported functions are "noisier" than they need to be. +.PP Bug reports should be mailed to .Cr "<tjg@star.le.ac.uk>" . .SH INCOMPATIBILITIES diff --git a/signal.c b/signal.c @@ -97,5 +97,7 @@ extern void initsignal() { h = sys_signal(SIGCLD, SIG_DFL); if (h != SIG_IGN && h != SIG_ERR) sys_signal(SIGCLD, h); + else + sighandlers[SIGCLD] = SIG_DFL; #endif }