Home | History | Annotate | Line # | Download | only in sh
eval.c revision 1.13
      1   1.1      cgd /*-
      2   1.7      jtc  * Copyright (c) 1993
      3   1.7      jtc  *	The Regents of the University of California.  All rights reserved.
      4   1.1      cgd  *
      5   1.1      cgd  * This code is derived from software contributed to Berkeley by
      6   1.1      cgd  * Kenneth Almquist.
      7   1.1      cgd  *
      8   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      9   1.1      cgd  * modification, are permitted provided that the following conditions
     10   1.1      cgd  * are met:
     11   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     12   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     13   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     15   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     16   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     17   1.1      cgd  *    must display the following acknowledgement:
     18   1.1      cgd  *	This product includes software developed by the University of
     19   1.1      cgd  *	California, Berkeley and its contributors.
     20   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     21   1.1      cgd  *    may be used to endorse or promote products derived from this software
     22   1.1      cgd  *    without specific prior written permission.
     23   1.1      cgd  *
     24   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34   1.1      cgd  * SUCH DAMAGE.
     35   1.1      cgd  */
     36   1.1      cgd 
     37   1.1      cgd #ifndef lint
     38  1.12  mycroft /*static char sccsid[] = "from: @(#)eval.c	8.1 (Berkeley) 5/31/93";*/
     39  1.13      jtc static char *rcsid = "$Id: eval.c,v 1.13 1994/06/12 02:31:28 jtc Exp $";
     40   1.1      cgd #endif /* not lint */
     41   1.1      cgd 
     42   1.1      cgd /*
     43   1.1      cgd  * Evaluate a command.
     44   1.1      cgd  */
     45   1.1      cgd 
     46   1.1      cgd #include "shell.h"
     47   1.1      cgd #include "nodes.h"
     48   1.1      cgd #include "syntax.h"
     49   1.1      cgd #include "expand.h"
     50   1.1      cgd #include "parser.h"
     51   1.1      cgd #include "jobs.h"
     52   1.1      cgd #include "eval.h"
     53   1.1      cgd #include "builtins.h"
     54   1.1      cgd #include "options.h"
     55   1.1      cgd #include "exec.h"
     56   1.1      cgd #include "redir.h"
     57   1.1      cgd #include "input.h"
     58   1.1      cgd #include "output.h"
     59   1.1      cgd #include "trap.h"
     60   1.1      cgd #include "var.h"
     61   1.1      cgd #include "memalloc.h"
     62   1.1      cgd #include "error.h"
     63   1.1      cgd #include "mystring.h"
     64  1.11      cgd #ifndef NO_HISTORY
     65   1.7      jtc #include "myhistedit.h"
     66  1.11      cgd #endif
     67   1.1      cgd #include <signal.h>
     68   1.9      jtc #include <unistd.h>
     69   1.1      cgd 
     70   1.1      cgd 
     71   1.1      cgd /* flags in argument to evaltree */
     72   1.1      cgd #define EV_EXIT 01		/* exit after evaluating tree */
     73   1.1      cgd #define EV_TESTED 02		/* exit status is checked; ignore -e flag */
     74   1.1      cgd #define EV_BACKCMD 04		/* command executing within back quotes */
     75   1.1      cgd 
     76   1.1      cgd 
     77   1.1      cgd /* reasons for skipping commands (see comment on breakcmd routine) */
     78   1.1      cgd #define SKIPBREAK 1
     79   1.1      cgd #define SKIPCONT 2
     80   1.1      cgd #define SKIPFUNC 3
     81   1.1      cgd 
     82   1.1      cgd MKINIT int evalskip;		/* set if we are skipping commands */
     83   1.1      cgd STATIC int skipcount;		/* number of levels to skip */
     84   1.1      cgd MKINIT int loopnest;		/* current loop nesting level */
     85   1.1      cgd int funcnest;			/* depth of function calls */
     86   1.1      cgd 
     87   1.1      cgd 
     88   1.1      cgd char *commandname;
     89   1.1      cgd struct strlist *cmdenviron;
     90   1.1      cgd int exitstatus;			/* exit status of last command */
     91   1.1      cgd 
     92   1.1      cgd 
     93   1.1      cgd #ifdef __STDC__
     94   1.1      cgd STATIC void evalloop(union node *);
     95   1.1      cgd STATIC void evalfor(union node *);
     96   1.1      cgd STATIC void evalcase(union node *, int);
     97   1.1      cgd STATIC void evalsubshell(union node *, int);
     98   1.1      cgd STATIC void expredir(union node *);
     99   1.1      cgd STATIC void evalpipe(union node *);
    100   1.1      cgd STATIC void evalcommand(union node *, int, struct backcmd *);
    101   1.1      cgd STATIC void prehash(union node *);
    102   1.1      cgd #else
    103   1.1      cgd STATIC void evalloop();
    104   1.1      cgd STATIC void evalfor();
    105   1.1      cgd STATIC void evalcase();
    106   1.1      cgd STATIC void evalsubshell();
    107   1.1      cgd STATIC void expredir();
    108   1.1      cgd STATIC void evalpipe();
    109   1.1      cgd STATIC void evalcommand();
    110   1.1      cgd STATIC void prehash();
    111   1.1      cgd #endif
    112   1.1      cgd 
    113   1.1      cgd 
    114   1.1      cgd 
    115   1.1      cgd /*
    116   1.1      cgd  * Called to reset things after an exception.
    117   1.1      cgd  */
    118   1.1      cgd 
    119   1.1      cgd #ifdef mkinit
    120   1.1      cgd INCLUDE "eval.h"
    121   1.1      cgd 
    122   1.1      cgd RESET {
    123   1.1      cgd 	evalskip = 0;
    124   1.1      cgd 	loopnest = 0;
    125   1.1      cgd 	funcnest = 0;
    126   1.1      cgd }
    127   1.1      cgd 
    128   1.1      cgd SHELLPROC {
    129   1.1      cgd 	exitstatus = 0;
    130   1.1      cgd }
    131   1.1      cgd #endif
    132   1.1      cgd 
    133   1.1      cgd 
    134   1.1      cgd 
    135   1.1      cgd /*
    136   1.1      cgd  * The eval commmand.
    137   1.1      cgd  */
    138   1.1      cgd 
    139   1.1      cgd evalcmd(argc, argv)
    140   1.1      cgd 	char **argv;
    141   1.1      cgd {
    142   1.1      cgd         char *p;
    143   1.1      cgd         char *concat;
    144   1.1      cgd         char **ap;
    145   1.1      cgd 
    146   1.1      cgd         if (argc > 1) {
    147   1.1      cgd                 p = argv[1];
    148   1.1      cgd                 if (argc > 2) {
    149   1.1      cgd                         STARTSTACKSTR(concat);
    150   1.1      cgd                         ap = argv + 2;
    151   1.1      cgd                         for (;;) {
    152   1.1      cgd                                 while (*p)
    153   1.1      cgd                                         STPUTC(*p++, concat);
    154   1.1      cgd                                 if ((p = *ap++) == NULL)
    155   1.1      cgd                                         break;
    156   1.1      cgd                                 STPUTC(' ', concat);
    157   1.1      cgd                         }
    158   1.1      cgd                         STPUTC('\0', concat);
    159   1.1      cgd                         p = grabstackstr(concat);
    160   1.1      cgd                 }
    161   1.1      cgd                 evalstring(p);
    162   1.1      cgd         }
    163   1.1      cgd         return exitstatus;
    164   1.1      cgd }
    165   1.1      cgd 
    166   1.1      cgd 
    167   1.1      cgd /*
    168   1.1      cgd  * Execute a command or commands contained in a string.
    169   1.1      cgd  */
    170   1.1      cgd 
    171   1.1      cgd void
    172   1.1      cgd evalstring(s)
    173   1.1      cgd 	char *s;
    174   1.1      cgd 	{
    175   1.1      cgd 	union node *n;
    176   1.1      cgd 	struct stackmark smark;
    177   1.1      cgd 
    178   1.1      cgd 	setstackmark(&smark);
    179   1.1      cgd 	setinputstring(s, 1);
    180   1.1      cgd 	while ((n = parsecmd(0)) != NEOF) {
    181   1.1      cgd 		evaltree(n, 0);
    182   1.1      cgd 		popstackmark(&smark);
    183   1.1      cgd 	}
    184   1.1      cgd 	popfile();
    185   1.1      cgd 	popstackmark(&smark);
    186   1.1      cgd }
    187   1.1      cgd 
    188   1.1      cgd 
    189   1.1      cgd 
    190   1.1      cgd /*
    191   1.1      cgd  * Evaluate a parse tree.  The value is left in the global variable
    192   1.1      cgd  * exitstatus.
    193   1.1      cgd  */
    194   1.1      cgd 
    195   1.1      cgd void
    196   1.1      cgd evaltree(n, flags)
    197   1.1      cgd 	union node *n;
    198   1.1      cgd 	{
    199   1.1      cgd 	if (n == NULL) {
    200   1.1      cgd 		TRACE(("evaltree(NULL) called\n"));
    201   1.7      jtc 		exitstatus = 0;
    202   1.7      jtc 		goto out;
    203   1.1      cgd 	}
    204  1.10      cgd #ifndef NO_HISTORY
    205   1.7      jtc 	displayhist = 1;	/* show history substitutions done with fc */
    206  1.10      cgd #endif
    207   1.1      cgd 	TRACE(("evaltree(0x%x: %d) called\n", (int)n, n->type));
    208   1.1      cgd 	switch (n->type) {
    209   1.1      cgd 	case NSEMI:
    210   1.1      cgd 		evaltree(n->nbinary.ch1, 0);
    211   1.1      cgd 		if (evalskip)
    212   1.1      cgd 			goto out;
    213   1.1      cgd 		evaltree(n->nbinary.ch2, flags);
    214   1.1      cgd 		break;
    215   1.1      cgd 	case NAND:
    216   1.1      cgd 		evaltree(n->nbinary.ch1, EV_TESTED);
    217   1.1      cgd 		if (evalskip || exitstatus != 0)
    218   1.1      cgd 			goto out;
    219   1.1      cgd 		evaltree(n->nbinary.ch2, flags);
    220   1.1      cgd 		break;
    221   1.1      cgd 	case NOR:
    222   1.1      cgd 		evaltree(n->nbinary.ch1, EV_TESTED);
    223   1.1      cgd 		if (evalskip || exitstatus == 0)
    224   1.1      cgd 			goto out;
    225   1.1      cgd 		evaltree(n->nbinary.ch2, flags);
    226   1.1      cgd 		break;
    227   1.1      cgd 	case NREDIR:
    228   1.1      cgd 		expredir(n->nredir.redirect);
    229   1.1      cgd 		redirect(n->nredir.redirect, REDIR_PUSH);
    230   1.1      cgd 		evaltree(n->nredir.n, flags);
    231   1.1      cgd 		popredir();
    232   1.1      cgd 		break;
    233   1.1      cgd 	case NSUBSHELL:
    234   1.1      cgd 		evalsubshell(n, flags);
    235   1.1      cgd 		break;
    236   1.1      cgd 	case NBACKGND:
    237   1.1      cgd 		evalsubshell(n, flags);
    238   1.1      cgd 		break;
    239   1.1      cgd 	case NIF: {
    240   1.1      cgd 		int status = 0;
    241   1.1      cgd 
    242   1.1      cgd 		evaltree(n->nif.test, EV_TESTED);
    243   1.1      cgd 		if (evalskip)
    244   1.1      cgd 			goto out;
    245   1.1      cgd 		if (exitstatus == 0) {
    246   1.1      cgd 			evaltree(n->nif.ifpart, flags);
    247   1.1      cgd 			status = exitstatus;
    248   1.1      cgd 		} else if (n->nif.elsepart) {
    249   1.1      cgd 			evaltree(n->nif.elsepart, flags);
    250   1.1      cgd 			status = exitstatus;
    251   1.1      cgd 		}
    252   1.1      cgd 		exitstatus = status;
    253   1.1      cgd 		break;
    254   1.1      cgd 	}
    255   1.1      cgd 	case NWHILE:
    256   1.1      cgd 	case NUNTIL:
    257   1.1      cgd 		evalloop(n);
    258   1.1      cgd 		break;
    259   1.1      cgd 	case NFOR:
    260   1.1      cgd 		evalfor(n);
    261   1.1      cgd 		break;
    262   1.1      cgd 	case NCASE:
    263   1.1      cgd 		evalcase(n, flags);
    264   1.1      cgd 		break;
    265   1.1      cgd 	case NDEFUN:
    266   1.1      cgd 		defun(n->narg.text, n->narg.next);
    267   1.1      cgd 		exitstatus = 0;
    268   1.1      cgd 		break;
    269   1.7      jtc 	case NNOT:
    270   1.7      jtc 		evaltree(n->nnot.com, EV_TESTED);
    271   1.7      jtc 		exitstatus = !exitstatus;
    272   1.7      jtc 		break;
    273   1.7      jtc 
    274   1.1      cgd 	case NPIPE:
    275   1.1      cgd 		evalpipe(n);
    276   1.1      cgd 		break;
    277   1.1      cgd 	case NCMD:
    278   1.1      cgd 		evalcommand(n, flags, (struct backcmd *)NULL);
    279   1.1      cgd 		break;
    280   1.1      cgd 	default:
    281   1.1      cgd 		out1fmt("Node type = %d\n", n->type);
    282   1.1      cgd 		flushout(&output);
    283   1.1      cgd 		break;
    284   1.1      cgd 	}
    285   1.1      cgd out:
    286   1.1      cgd 	if (pendingsigs)
    287   1.1      cgd 		dotrap();
    288   1.1      cgd 	if ((flags & EV_EXIT) || (eflag && exitstatus && !(flags & EV_TESTED)))
    289   1.1      cgd 		exitshell(exitstatus);
    290   1.1      cgd }
    291   1.1      cgd 
    292   1.1      cgd 
    293   1.1      cgd STATIC void
    294   1.1      cgd evalloop(n)
    295   1.1      cgd 	union node *n;
    296   1.1      cgd 	{
    297   1.1      cgd 	int status;
    298   1.1      cgd 
    299   1.1      cgd 	loopnest++;
    300   1.1      cgd 	status = 0;
    301   1.1      cgd 	for (;;) {
    302   1.1      cgd 		evaltree(n->nbinary.ch1, EV_TESTED);
    303   1.1      cgd 		if (evalskip) {
    304   1.1      cgd skipping:	  if (evalskip == SKIPCONT && --skipcount <= 0) {
    305   1.1      cgd 				evalskip = 0;
    306   1.1      cgd 				continue;
    307   1.1      cgd 			}
    308   1.1      cgd 			if (evalskip == SKIPBREAK && --skipcount <= 0)
    309   1.1      cgd 				evalskip = 0;
    310   1.1      cgd 			break;
    311   1.1      cgd 		}
    312   1.1      cgd 		if (n->type == NWHILE) {
    313   1.1      cgd 			if (exitstatus != 0)
    314   1.1      cgd 				break;
    315   1.1      cgd 		} else {
    316   1.1      cgd 			if (exitstatus == 0)
    317   1.1      cgd 				break;
    318   1.1      cgd 		}
    319   1.1      cgd 		evaltree(n->nbinary.ch2, 0);
    320   1.1      cgd 		status = exitstatus;
    321   1.1      cgd 		if (evalskip)
    322   1.1      cgd 			goto skipping;
    323   1.1      cgd 	}
    324   1.1      cgd 	loopnest--;
    325   1.1      cgd 	exitstatus = status;
    326   1.1      cgd }
    327   1.1      cgd 
    328   1.1      cgd 
    329   1.1      cgd 
    330   1.1      cgd STATIC void
    331   1.1      cgd evalfor(n)
    332   1.1      cgd 	union node *n;
    333   1.1      cgd 	{
    334   1.1      cgd 	struct arglist arglist;
    335   1.1      cgd 	union node *argp;
    336   1.1      cgd 	struct strlist *sp;
    337   1.1      cgd 	struct stackmark smark;
    338   1.1      cgd 
    339   1.1      cgd 	setstackmark(&smark);
    340   1.1      cgd 	arglist.lastp = &arglist.list;
    341   1.1      cgd 	for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
    342   1.7      jtc 		expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
    343   1.1      cgd 		if (evalskip)
    344   1.1      cgd 			goto out;
    345   1.1      cgd 	}
    346   1.1      cgd 	*arglist.lastp = NULL;
    347   1.1      cgd 
    348   1.1      cgd 	exitstatus = 0;
    349   1.1      cgd 	loopnest++;
    350   1.1      cgd 	for (sp = arglist.list ; sp ; sp = sp->next) {
    351   1.1      cgd 		setvar(n->nfor.var, sp->text, 0);
    352   1.1      cgd 		evaltree(n->nfor.body, 0);
    353   1.1      cgd 		if (evalskip) {
    354   1.1      cgd 			if (evalskip == SKIPCONT && --skipcount <= 0) {
    355   1.1      cgd 				evalskip = 0;
    356   1.1      cgd 				continue;
    357   1.1      cgd 			}
    358   1.1      cgd 			if (evalskip == SKIPBREAK && --skipcount <= 0)
    359   1.1      cgd 				evalskip = 0;
    360   1.1      cgd 			break;
    361   1.1      cgd 		}
    362   1.1      cgd 	}
    363   1.1      cgd 	loopnest--;
    364   1.1      cgd out:
    365   1.1      cgd 	popstackmark(&smark);
    366   1.1      cgd }
    367   1.1      cgd 
    368   1.1      cgd 
    369   1.1      cgd 
    370   1.1      cgd STATIC void
    371   1.1      cgd evalcase(n, flags)
    372   1.1      cgd 	union node *n;
    373   1.1      cgd 	{
    374   1.1      cgd 	union node *cp;
    375   1.1      cgd 	union node *patp;
    376   1.1      cgd 	struct arglist arglist;
    377   1.1      cgd 	struct stackmark smark;
    378   1.1      cgd 
    379   1.1      cgd 	setstackmark(&smark);
    380   1.1      cgd 	arglist.lastp = &arglist.list;
    381   1.7      jtc 	expandarg(n->ncase.expr, &arglist, EXP_TILDE);
    382   1.1      cgd 	for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
    383   1.1      cgd 		for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
    384   1.1      cgd 			if (casematch(patp, arglist.list->text)) {
    385   1.1      cgd 				if (evalskip == 0) {
    386   1.1      cgd 					evaltree(cp->nclist.body, flags);
    387   1.1      cgd 				}
    388   1.1      cgd 				goto out;
    389   1.1      cgd 			}
    390   1.1      cgd 		}
    391   1.1      cgd 	}
    392   1.1      cgd out:
    393   1.1      cgd 	popstackmark(&smark);
    394   1.1      cgd }
    395   1.1      cgd 
    396   1.1      cgd 
    397   1.1      cgd 
    398   1.1      cgd /*
    399   1.1      cgd  * Kick off a subshell to evaluate a tree.
    400   1.1      cgd  */
    401   1.1      cgd 
    402   1.1      cgd STATIC void
    403   1.1      cgd evalsubshell(n, flags)
    404   1.1      cgd 	union node *n;
    405   1.1      cgd 	{
    406   1.1      cgd 	struct job *jp;
    407   1.1      cgd 	int backgnd = (n->type == NBACKGND);
    408   1.1      cgd 
    409   1.1      cgd 	expredir(n->nredir.redirect);
    410   1.1      cgd 	jp = makejob(n, 1);
    411   1.1      cgd 	if (forkshell(jp, n, backgnd) == 0) {
    412   1.1      cgd 		if (backgnd)
    413   1.1      cgd 			flags &=~ EV_TESTED;
    414   1.1      cgd 		redirect(n->nredir.redirect, 0);
    415   1.1      cgd 		evaltree(n->nredir.n, flags | EV_EXIT);	/* never returns */
    416   1.1      cgd 	}
    417   1.1      cgd 	if (! backgnd) {
    418   1.1      cgd 		INTOFF;
    419   1.1      cgd 		exitstatus = waitforjob(jp);
    420   1.1      cgd 		INTON;
    421   1.1      cgd 	}
    422   1.1      cgd }
    423   1.1      cgd 
    424   1.1      cgd 
    425   1.1      cgd 
    426   1.1      cgd /*
    427   1.1      cgd  * Compute the names of the files in a redirection list.
    428   1.1      cgd  */
    429   1.1      cgd 
    430   1.1      cgd STATIC void
    431   1.1      cgd expredir(n)
    432   1.1      cgd 	union node *n;
    433   1.1      cgd 	{
    434   1.1      cgd 	register union node *redir;
    435   1.1      cgd 
    436   1.1      cgd 	for (redir = n ; redir ; redir = redir->nfile.next) {
    437   1.1      cgd 		if (redir->type == NFROM
    438   1.1      cgd 		 || redir->type == NTO
    439   1.1      cgd 		 || redir->type == NAPPEND) {
    440   1.1      cgd 			struct arglist fn;
    441   1.1      cgd 			fn.lastp = &fn.list;
    442   1.7      jtc 			expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
    443   1.1      cgd 			redir->nfile.expfname = fn.list->text;
    444   1.1      cgd 		}
    445   1.1      cgd 	}
    446   1.1      cgd }
    447   1.1      cgd 
    448   1.1      cgd 
    449   1.1      cgd 
    450   1.1      cgd /*
    451   1.1      cgd  * Evaluate a pipeline.  All the processes in the pipeline are children
    452   1.1      cgd  * of the process creating the pipeline.  (This differs from some versions
    453   1.1      cgd  * of the shell, which make the last process in a pipeline the parent
    454   1.1      cgd  * of all the rest.)
    455   1.1      cgd  */
    456   1.1      cgd 
    457   1.1      cgd STATIC void
    458   1.1      cgd evalpipe(n)
    459   1.1      cgd 	union node *n;
    460   1.1      cgd 	{
    461   1.1      cgd 	struct job *jp;
    462   1.1      cgd 	struct nodelist *lp;
    463   1.1      cgd 	int pipelen;
    464   1.1      cgd 	int prevfd;
    465   1.1      cgd 	int pip[2];
    466   1.1      cgd 
    467   1.1      cgd 	TRACE(("evalpipe(0x%x) called\n", (int)n));
    468   1.1      cgd 	pipelen = 0;
    469   1.1      cgd 	for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
    470   1.1      cgd 		pipelen++;
    471   1.1      cgd 	INTOFF;
    472   1.1      cgd 	jp = makejob(n, pipelen);
    473   1.1      cgd 	prevfd = -1;
    474   1.1      cgd 	for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
    475   1.1      cgd 		prehash(lp->n);
    476   1.1      cgd 		pip[1] = -1;
    477   1.1      cgd 		if (lp->next) {
    478   1.1      cgd 			if (pipe(pip) < 0) {
    479   1.1      cgd 				close(prevfd);
    480   1.1      cgd 				error("Pipe call failed");
    481   1.1      cgd 			}
    482   1.1      cgd 		}
    483   1.1      cgd 		if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
    484   1.1      cgd 			INTON;
    485   1.1      cgd 			if (prevfd > 0) {
    486   1.1      cgd 				close(0);
    487   1.1      cgd 				copyfd(prevfd, 0);
    488   1.1      cgd 				close(prevfd);
    489   1.1      cgd 			}
    490   1.1      cgd 			if (pip[1] >= 0) {
    491   1.1      cgd 				close(pip[0]);
    492   1.1      cgd 				if (pip[1] != 1) {
    493   1.1      cgd 					close(1);
    494   1.1      cgd 					copyfd(pip[1], 1);
    495   1.1      cgd 					close(pip[1]);
    496   1.1      cgd 				}
    497   1.1      cgd 			}
    498   1.1      cgd 			evaltree(lp->n, EV_EXIT);
    499   1.1      cgd 		}
    500   1.1      cgd 		if (prevfd >= 0)
    501   1.1      cgd 			close(prevfd);
    502   1.1      cgd 		prevfd = pip[0];
    503   1.1      cgd 		close(pip[1]);
    504   1.1      cgd 	}
    505   1.1      cgd 	INTON;
    506   1.1      cgd 	if (n->npipe.backgnd == 0) {
    507   1.1      cgd 		INTOFF;
    508   1.1      cgd 		exitstatus = waitforjob(jp);
    509   1.1      cgd 		TRACE(("evalpipe:  job done exit status %d\n", exitstatus));
    510   1.1      cgd 		INTON;
    511   1.1      cgd 	}
    512   1.1      cgd }
    513   1.1      cgd 
    514   1.1      cgd 
    515   1.1      cgd 
    516   1.1      cgd /*
    517   1.1      cgd  * Execute a command inside back quotes.  If it's a builtin command, we
    518   1.1      cgd  * want to save its output in a block obtained from malloc.  Otherwise
    519   1.1      cgd  * we fork off a subprocess and get the output of the command via a pipe.
    520   1.1      cgd  * Should be called with interrupts off.
    521   1.1      cgd  */
    522   1.1      cgd 
    523   1.1      cgd void
    524   1.1      cgd evalbackcmd(n, result)
    525   1.1      cgd 	union node *n;
    526   1.1      cgd 	struct backcmd *result;
    527   1.1      cgd 	{
    528   1.1      cgd 	int pip[2];
    529   1.1      cgd 	struct job *jp;
    530   1.1      cgd 	struct stackmark smark;		/* unnecessary */
    531   1.1      cgd 
    532   1.1      cgd 	setstackmark(&smark);
    533   1.1      cgd 	result->fd = -1;
    534   1.1      cgd 	result->buf = NULL;
    535   1.1      cgd 	result->nleft = 0;
    536   1.1      cgd 	result->jp = NULL;
    537   1.7      jtc 	exitstatus = 0;
    538   1.6      cgd 	if (n == NULL)
    539   1.7      jtc 		goto out;
    540   1.7      jtc 	if (n->type == NCMD) {
    541   1.1      cgd 		evalcommand(n, EV_BACKCMD, result);
    542   1.1      cgd 	} else {
    543   1.1      cgd 		if (pipe(pip) < 0)
    544   1.1      cgd 			error("Pipe call failed");
    545   1.1      cgd 		jp = makejob(n, 1);
    546   1.1      cgd 		if (forkshell(jp, n, FORK_NOJOB) == 0) {
    547   1.1      cgd 			FORCEINTON;
    548   1.1      cgd 			close(pip[0]);
    549   1.1      cgd 			if (pip[1] != 1) {
    550   1.1      cgd 				close(1);
    551   1.1      cgd 				copyfd(pip[1], 1);
    552   1.1      cgd 				close(pip[1]);
    553   1.1      cgd 			}
    554   1.1      cgd 			evaltree(n, EV_EXIT);
    555   1.1      cgd 		}
    556   1.1      cgd 		close(pip[1]);
    557   1.1      cgd 		result->fd = pip[0];
    558   1.1      cgd 		result->jp = jp;
    559   1.1      cgd 	}
    560   1.7      jtc out:
    561   1.1      cgd 	popstackmark(&smark);
    562   1.1      cgd 	TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
    563   1.1      cgd 		result->fd, result->buf, result->nleft, result->jp));
    564   1.1      cgd }
    565   1.1      cgd 
    566   1.1      cgd 
    567   1.1      cgd 
    568   1.1      cgd /*
    569   1.1      cgd  * Execute a simple command.
    570   1.1      cgd  */
    571   1.1      cgd 
    572   1.1      cgd STATIC void
    573   1.1      cgd evalcommand(cmd, flags, backcmd)
    574   1.1      cgd 	union node *cmd;
    575   1.1      cgd 	struct backcmd *backcmd;
    576   1.1      cgd 	{
    577   1.1      cgd 	struct stackmark smark;
    578   1.1      cgd 	union node *argp;
    579   1.1      cgd 	struct arglist arglist;
    580   1.1      cgd 	struct arglist varlist;
    581   1.1      cgd 	char **argv;
    582   1.1      cgd 	int argc;
    583   1.1      cgd 	char **envp;
    584   1.1      cgd 	int varflag;
    585   1.1      cgd 	struct strlist *sp;
    586   1.1      cgd 	register char *p;
    587   1.1      cgd 	int mode;
    588   1.1      cgd 	int pip[2];
    589   1.1      cgd 	struct cmdentry cmdentry;
    590   1.1      cgd 	struct job *jp;
    591   1.1      cgd 	struct jmploc jmploc;
    592   1.1      cgd 	struct jmploc *volatile savehandler;
    593   1.1      cgd 	char *volatile savecmdname;
    594   1.1      cgd 	volatile struct shparam saveparam;
    595   1.1      cgd 	struct localvar *volatile savelocalvars;
    596   1.1      cgd 	volatile int e;
    597   1.1      cgd 	char *lastarg;
    598   1.1      cgd 
    599   1.1      cgd 	/* First expand the arguments. */
    600   1.1      cgd 	TRACE(("evalcommand(0x%x, %d) called\n", (int)cmd, flags));
    601   1.1      cgd 	setstackmark(&smark);
    602   1.1      cgd 	arglist.lastp = &arglist.list;
    603   1.1      cgd 	varlist.lastp = &varlist.list;
    604   1.1      cgd 	varflag = 1;
    605   1.1      cgd 	for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
    606   1.1      cgd 		p = argp->narg.text;
    607   1.1      cgd 		if (varflag && is_name(*p)) {
    608   1.1      cgd 			do {
    609   1.1      cgd 				p++;
    610   1.1      cgd 			} while (is_in_name(*p));
    611   1.1      cgd 			if (*p == '=') {
    612   1.7      jtc 				expandarg(argp, &varlist, EXP_VARTILDE);
    613   1.1      cgd 				continue;
    614   1.1      cgd 			}
    615   1.1      cgd 		}
    616   1.7      jtc 		expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
    617   1.1      cgd 		varflag = 0;
    618   1.1      cgd 	}
    619   1.1      cgd 	*arglist.lastp = NULL;
    620   1.1      cgd 	*varlist.lastp = NULL;
    621   1.1      cgd 	expredir(cmd->ncmd.redirect);
    622   1.1      cgd 	argc = 0;
    623   1.1      cgd 	for (sp = arglist.list ; sp ; sp = sp->next)
    624   1.1      cgd 		argc++;
    625   1.1      cgd 	argv = stalloc(sizeof (char *) * (argc + 1));
    626   1.7      jtc 
    627   1.7      jtc 	for (sp = arglist.list ; sp ; sp = sp->next) {
    628   1.7      jtc 		TRACE(("evalcommand arg: %s\n", sp->text));
    629   1.1      cgd 		*argv++ = sp->text;
    630   1.7      jtc 	}
    631   1.1      cgd 	*argv = NULL;
    632   1.1      cgd 	lastarg = NULL;
    633   1.1      cgd 	if (iflag && funcnest == 0 && argc > 0)
    634   1.1      cgd 		lastarg = argv[-1];
    635   1.1      cgd 	argv -= argc;
    636   1.1      cgd 
    637   1.1      cgd 	/* Print the command if xflag is set. */
    638   1.1      cgd 	if (xflag) {
    639   1.1      cgd 		outc('+', &errout);
    640   1.1      cgd 		for (sp = varlist.list ; sp ; sp = sp->next) {
    641   1.1      cgd 			outc(' ', &errout);
    642   1.1      cgd 			out2str(sp->text);
    643   1.1      cgd 		}
    644   1.1      cgd 		for (sp = arglist.list ; sp ; sp = sp->next) {
    645   1.1      cgd 			outc(' ', &errout);
    646   1.1      cgd 			out2str(sp->text);
    647   1.1      cgd 		}
    648   1.1      cgd 		outc('\n', &errout);
    649   1.1      cgd 		flushout(&errout);
    650   1.1      cgd 	}
    651   1.1      cgd 
    652   1.1      cgd 	/* Now locate the command. */
    653   1.1      cgd 	if (argc == 0) {
    654   1.1      cgd 		cmdentry.cmdtype = CMDBUILTIN;
    655   1.1      cgd 		cmdentry.u.index = BLTINCMD;
    656   1.1      cgd 	} else {
    657   1.1      cgd 		find_command(argv[0], &cmdentry, 1);
    658   1.1      cgd 		if (cmdentry.cmdtype == CMDUNKNOWN) {	/* command not found */
    659   1.1      cgd 			exitstatus = 2;
    660   1.1      cgd 			flushout(&errout);
    661   1.1      cgd 			return;
    662   1.1      cgd 		}
    663   1.1      cgd 		/* implement the bltin builtin here */
    664   1.1      cgd 		if (cmdentry.cmdtype == CMDBUILTIN && cmdentry.u.index == BLTINCMD) {
    665   1.1      cgd 			for (;;) {
    666   1.1      cgd 				argv++;
    667   1.1      cgd 				if (--argc == 0)
    668   1.1      cgd 					break;
    669   1.1      cgd 				if ((cmdentry.u.index = find_builtin(*argv)) < 0) {
    670   1.1      cgd 					outfmt(&errout, "%s: not found\n", *argv);
    671   1.1      cgd 					exitstatus = 2;
    672   1.1      cgd 					flushout(&errout);
    673   1.1      cgd 					return;
    674   1.1      cgd 				}
    675   1.1      cgd 				if (cmdentry.u.index != BLTINCMD)
    676   1.1      cgd 					break;
    677   1.1      cgd 			}
    678   1.1      cgd 		}
    679   1.1      cgd 	}
    680   1.1      cgd 
    681   1.1      cgd 	/* Fork off a child process if necessary. */
    682   1.1      cgd 	if (cmd->ncmd.backgnd
    683   1.1      cgd 	 || cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0
    684   1.1      cgd 	 || (flags & EV_BACKCMD) != 0
    685   1.1      cgd 	    && (cmdentry.cmdtype != CMDBUILTIN
    686   1.1      cgd 		 || cmdentry.u.index == DOTCMD
    687   1.1      cgd 		 || cmdentry.u.index == EVALCMD)) {
    688   1.1      cgd 		jp = makejob(cmd, 1);
    689   1.1      cgd 		mode = cmd->ncmd.backgnd;
    690   1.1      cgd 		if (flags & EV_BACKCMD) {
    691   1.1      cgd 			mode = FORK_NOJOB;
    692   1.1      cgd 			if (pipe(pip) < 0)
    693   1.1      cgd 				error("Pipe call failed");
    694   1.1      cgd 		}
    695   1.1      cgd 		if (forkshell(jp, cmd, mode) != 0)
    696   1.1      cgd 			goto parent;	/* at end of routine */
    697   1.1      cgd 		if (flags & EV_BACKCMD) {
    698   1.1      cgd 			FORCEINTON;
    699   1.1      cgd 			close(pip[0]);
    700   1.1      cgd 			if (pip[1] != 1) {
    701   1.1      cgd 				close(1);
    702   1.1      cgd 				copyfd(pip[1], 1);
    703   1.1      cgd 				close(pip[1]);
    704   1.1      cgd 			}
    705   1.1      cgd 		}
    706   1.1      cgd 		flags |= EV_EXIT;
    707   1.1      cgd 	}
    708   1.1      cgd 
    709   1.1      cgd 	/* This is the child process if a fork occurred. */
    710   1.1      cgd 	/* Execute the command. */
    711   1.1      cgd 	if (cmdentry.cmdtype == CMDFUNCTION) {
    712   1.1      cgd 		trputs("Shell function:  ");  trargs(argv);
    713   1.1      cgd 		redirect(cmd->ncmd.redirect, REDIR_PUSH);
    714   1.1      cgd 		saveparam = shellparam;
    715   1.1      cgd 		shellparam.malloc = 0;
    716   1.1      cgd 		shellparam.nparam = argc - 1;
    717   1.1      cgd 		shellparam.p = argv + 1;
    718   1.1      cgd 		shellparam.optnext = NULL;
    719   1.1      cgd 		INTOFF;
    720   1.1      cgd 		savelocalvars = localvars;
    721   1.1      cgd 		localvars = NULL;
    722   1.1      cgd 		INTON;
    723   1.1      cgd 		if (setjmp(jmploc.loc)) {
    724   1.1      cgd 			if (exception == EXSHELLPROC)
    725   1.1      cgd 				freeparam((struct shparam *)&saveparam);
    726   1.1      cgd 			else {
    727   1.1      cgd 				freeparam(&shellparam);
    728   1.1      cgd 				shellparam = saveparam;
    729   1.1      cgd 			}
    730   1.1      cgd 			poplocalvars();
    731   1.1      cgd 			localvars = savelocalvars;
    732   1.1      cgd 			handler = savehandler;
    733   1.1      cgd 			longjmp(handler->loc, 1);
    734   1.1      cgd 		}
    735   1.1      cgd 		savehandler = handler;
    736   1.1      cgd 		handler = &jmploc;
    737   1.1      cgd 		for (sp = varlist.list ; sp ; sp = sp->next)
    738   1.1      cgd 			mklocal(sp->text);
    739   1.1      cgd 		funcnest++;
    740   1.1      cgd 		evaltree(cmdentry.u.func, 0);
    741   1.1      cgd 		funcnest--;
    742   1.1      cgd 		INTOFF;
    743   1.1      cgd 		poplocalvars();
    744   1.1      cgd 		localvars = savelocalvars;
    745   1.1      cgd 		freeparam(&shellparam);
    746   1.1      cgd 		shellparam = saveparam;
    747   1.1      cgd 		handler = savehandler;
    748   1.1      cgd 		popredir();
    749   1.1      cgd 		INTON;
    750   1.1      cgd 		if (evalskip == SKIPFUNC) {
    751   1.1      cgd 			evalskip = 0;
    752   1.1      cgd 			skipcount = 0;
    753   1.1      cgd 		}
    754   1.1      cgd 		if (flags & EV_EXIT)
    755   1.1      cgd 			exitshell(exitstatus);
    756   1.1      cgd 	} else if (cmdentry.cmdtype == CMDBUILTIN) {
    757   1.1      cgd 		trputs("builtin command:  ");  trargs(argv);
    758   1.1      cgd 		mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
    759   1.1      cgd 		if (flags == EV_BACKCMD) {
    760   1.1      cgd 			memout.nleft = 0;
    761   1.1      cgd 			memout.nextc = memout.buf;
    762   1.1      cgd 			memout.bufsize = 64;
    763   1.1      cgd 			mode |= REDIR_BACKQ;
    764   1.1      cgd 		}
    765   1.1      cgd 		redirect(cmd->ncmd.redirect, mode);
    766   1.1      cgd 		savecmdname = commandname;
    767   1.1      cgd 		cmdenviron = varlist.list;
    768   1.1      cgd 		e = -1;
    769   1.1      cgd 		if (setjmp(jmploc.loc)) {
    770   1.1      cgd 			e = exception;
    771   1.1      cgd 			exitstatus = (e == EXINT)? SIGINT+128 : 2;
    772   1.1      cgd 			goto cmddone;
    773   1.1      cgd 		}
    774   1.1      cgd 		savehandler = handler;
    775   1.1      cgd 		handler = &jmploc;
    776   1.1      cgd 		commandname = argv[0];
    777   1.1      cgd 		argptr = argv + 1;
    778   1.1      cgd 		optptr = NULL;			/* initialize nextopt */
    779   1.1      cgd 		exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
    780   1.1      cgd 		flushall();
    781   1.1      cgd cmddone:
    782   1.1      cgd 		out1 = &output;
    783   1.1      cgd 		out2 = &errout;
    784   1.1      cgd 		freestdout();
    785   1.1      cgd 		if (e != EXSHELLPROC) {
    786   1.1      cgd 			commandname = savecmdname;
    787   1.1      cgd 			if (flags & EV_EXIT) {
    788   1.1      cgd 				exitshell(exitstatus);
    789   1.1      cgd 			}
    790   1.1      cgd 		}
    791   1.1      cgd 		handler = savehandler;
    792   1.1      cgd 		if (e != -1) {
    793   1.1      cgd 			if (e != EXERROR || cmdentry.u.index == BLTINCMD
    794   1.1      cgd 					       || cmdentry.u.index == DOTCMD
    795   1.1      cgd 					       || cmdentry.u.index == EVALCMD
    796  1.10      cgd #ifndef NO_HISTORY
    797   1.7      jtc 					       || cmdentry.u.index == HISTCMD
    798  1.10      cgd #endif
    799   1.1      cgd 					       || cmdentry.u.index == EXECCMD)
    800   1.1      cgd 				exraise(e);
    801   1.1      cgd 			FORCEINTON;
    802   1.1      cgd 		}
    803   1.1      cgd 		if (cmdentry.u.index != EXECCMD)
    804   1.1      cgd 			popredir();
    805   1.1      cgd 		if (flags == EV_BACKCMD) {
    806   1.1      cgd 			backcmd->buf = memout.buf;
    807   1.1      cgd 			backcmd->nleft = memout.nextc - memout.buf;
    808   1.1      cgd 			memout.buf = NULL;
    809   1.1      cgd 		}
    810   1.1      cgd 	} else {
    811   1.1      cgd 		trputs("normal command:  ");  trargs(argv);
    812   1.1      cgd 		clearredir();
    813   1.1      cgd 		redirect(cmd->ncmd.redirect, 0);
    814   1.1      cgd 		if (varlist.list) {
    815   1.1      cgd 			p = stalloc(strlen(pathval()) + 1);
    816   1.1      cgd 			scopy(pathval(), p);
    817   1.1      cgd 		} else {
    818   1.1      cgd 			p = pathval();
    819   1.1      cgd 		}
    820   1.1      cgd 		for (sp = varlist.list ; sp ; sp = sp->next)
    821   1.1      cgd 			setvareq(sp->text, VEXPORT|VSTACK);
    822   1.1      cgd 		envp = environment();
    823   1.1      cgd 		shellexec(argv, envp, p, cmdentry.u.index);
    824   1.1      cgd 		/*NOTREACHED*/
    825   1.1      cgd 	}
    826   1.1      cgd 	goto out;
    827   1.1      cgd 
    828   1.1      cgd parent:	/* parent process gets here (if we forked) */
    829   1.1      cgd 	if (mode == 0) {	/* argument to fork */
    830   1.1      cgd 		INTOFF;
    831   1.1      cgd 		exitstatus = waitforjob(jp);
    832   1.1      cgd 		INTON;
    833   1.1      cgd 	} else if (mode == 2) {
    834   1.1      cgd 		backcmd->fd = pip[0];
    835   1.1      cgd 		close(pip[1]);
    836   1.1      cgd 		backcmd->jp = jp;
    837   1.1      cgd 	}
    838   1.1      cgd 
    839   1.1      cgd out:
    840   1.1      cgd 	if (lastarg)
    841   1.1      cgd 		setvar("_", lastarg, 0);
    842   1.1      cgd 	popstackmark(&smark);
    843   1.1      cgd }
    844   1.1      cgd 
    845   1.1      cgd 
    846   1.1      cgd 
    847   1.1      cgd /*
    848   1.1      cgd  * Search for a command.  This is called before we fork so that the
    849   1.1      cgd  * location of the command will be available in the parent as well as
    850   1.1      cgd  * the child.  The check for "goodname" is an overly conservative
    851   1.1      cgd  * check that the name will not be subject to expansion.
    852   1.1      cgd  */
    853   1.1      cgd 
    854   1.1      cgd STATIC void
    855   1.1      cgd prehash(n)
    856   1.1      cgd 	union node *n;
    857   1.1      cgd 	{
    858   1.1      cgd 	struct cmdentry entry;
    859   1.1      cgd 
    860   1.1      cgd 	if (n->type == NCMD && goodname(n->ncmd.args->narg.text))
    861   1.1      cgd 		find_command(n->ncmd.args->narg.text, &entry, 0);
    862   1.1      cgd }
    863   1.1      cgd 
    864   1.1      cgd 
    865   1.1      cgd 
    866   1.1      cgd /*
    867   1.1      cgd  * Builtin commands.  Builtin commands whose functions are closely
    868   1.1      cgd  * tied to evaluation are implemented here.
    869   1.1      cgd  */
    870   1.1      cgd 
    871   1.1      cgd /*
    872   1.1      cgd  * No command given, or a bltin command with no arguments.  Set the
    873   1.1      cgd  * specified variables.
    874   1.1      cgd  */
    875   1.1      cgd 
    876   1.1      cgd bltincmd(argc, argv)  char **argv; {
    877   1.1      cgd 	listsetvar(cmdenviron);
    878  1.13      jtc 	return 0;
    879   1.1      cgd }
    880   1.1      cgd 
    881   1.1      cgd 
    882   1.1      cgd /*
    883   1.1      cgd  * Handle break and continue commands.  Break, continue, and return are
    884   1.1      cgd  * all handled by setting the evalskip flag.  The evaluation routines
    885   1.1      cgd  * above all check this flag, and if it is set they start skipping
    886   1.1      cgd  * commands rather than executing them.  The variable skipcount is
    887   1.1      cgd  * the number of loops to break/continue, or the number of function
    888   1.1      cgd  * levels to return.  (The latter is always 1.)  It should probably
    889   1.1      cgd  * be an error to break out of more loops than exist, but it isn't
    890   1.1      cgd  * in the standard shell so we don't make it one here.
    891   1.1      cgd  */
    892   1.1      cgd 
    893   1.1      cgd breakcmd(argc, argv)  char **argv; {
    894   1.1      cgd 	int n;
    895   1.1      cgd 
    896   1.1      cgd 	n = 1;
    897   1.1      cgd 	if (argc > 1)
    898   1.1      cgd 		n = number(argv[1]);
    899   1.1      cgd 	if (n > loopnest)
    900   1.1      cgd 		n = loopnest;
    901   1.1      cgd 	if (n > 0) {
    902   1.1      cgd 		evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
    903   1.1      cgd 		skipcount = n;
    904   1.1      cgd 	}
    905   1.1      cgd 	return 0;
    906   1.1      cgd }
    907   1.1      cgd 
    908   1.1      cgd 
    909   1.1      cgd /*
    910   1.1      cgd  * The return command.
    911   1.1      cgd  */
    912   1.1      cgd 
    913   1.1      cgd returncmd(argc, argv)  char **argv; {
    914   1.1      cgd 	int ret;
    915   1.1      cgd 
    916   1.1      cgd 	ret = exitstatus;
    917   1.1      cgd 	if (argc > 1)
    918   1.1      cgd 		ret = number(argv[1]);
    919   1.1      cgd 	if (funcnest) {
    920   1.1      cgd 		evalskip = SKIPFUNC;
    921   1.1      cgd 		skipcount = 1;
    922   1.1      cgd 	}
    923   1.1      cgd 	return ret;
    924   1.1      cgd }
    925   1.1      cgd 
    926   1.1      cgd 
    927   1.8      jtc falsecmd(argc, argv)  char **argv; {
    928   1.8      jtc 	return 1;
    929   1.8      jtc }
    930   1.8      jtc 
    931   1.8      jtc 
    932   1.1      cgd truecmd(argc, argv)  char **argv; {
    933   1.1      cgd 	return 0;
    934   1.1      cgd }
    935   1.1      cgd 
    936   1.1      cgd 
    937   1.1      cgd execcmd(argc, argv)  char **argv; {
    938   1.1      cgd 	if (argc > 1) {
    939   1.1      cgd 		iflag = 0;		/* exit on error */
    940   1.7      jtc 		mflag = 0;
    941   1.7      jtc 		optschanged();
    942   1.1      cgd 		shellexec(argv + 1, environment(), pathval(), 0);
    943   1.1      cgd 
    944   1.1      cgd 	}
    945   1.1      cgd 	return 0;
    946   1.1      cgd }
    947