3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)eval.c 8.9 (Berkeley) 6/8/95
37 * $FreeBSD: src/bin/sh/eval.c,v 1.117 2012/01/15 21:39:38 jilles Exp $
41 #include <sys/resource.h>
42 #include <sys/wait.h> /* For WIFSIGNALED(status) */
74 #include "myhistedit.h"
78 int evalskip; /* set if we are skipping commands */
79 static int skipcount; /* number of levels to skip */
80 MKINIT int loopnest; /* current loop nesting level */
81 int funcnest; /* depth of function calls */
82 static int builtin_flags; /* evalcommand flags for builtins */
85 const char *commandname;
86 struct strlist *cmdenviron;
87 int exitstatus; /* exit status of last command */
88 int oexitstatus; /* saved exit status */
91 static void evalloop(union node *, int);
92 static void evalfor(union node *, int);
93 static union node *evalcase(union node *);
94 static void evalsubshell(union node *, int);
95 static void evalredir(union node *, int);
96 static void expredir(union node *);
97 static void evalpipe(union node *);
98 static int is_valid_fast_cmdsubst(union node *n);
99 static void evalcommand(union node *, int, struct backcmd *);
100 static void prehash(union node *);
104 * Called to reset things after an exception.
124 evalcmd(int argc, char **argv)
133 STARTSTACKSTR(concat);
137 if ((p = *ap++) == NULL)
141 STPUTC('\0', concat);
142 p = grabstackstr(concat);
144 evalstring(p, builtin_flags);
152 * Execute a command or commands contained in a string.
156 evalstring(char *s, int flags)
159 struct stackmark smark;
163 flags_exit = flags & EV_EXIT;
166 setstackmark(&smark);
167 setinputstring(s, 1);
168 while ((n = parsecmd(0)) != NEOF) {
169 if (n != NULL && !nflag) {
170 if (flags_exit && preadateof())
171 evaltree(n, flags | EV_EXIT);
176 popstackmark(&smark);
179 popstackmark(&smark);
188 * Evaluate a parse tree. The value is left in the global variable
193 evaltree(union node *n, int flags)
200 TRACE(("evaltree(NULL) called\n"));
207 displayhist = 1; /* show history substitutions done with fc */
209 TRACE(("evaltree(%p: %d) called\n", (void *)n, n->type));
212 evaltree(n->nbinary.ch1, flags & ~EV_EXIT);
215 next = n->nbinary.ch2;
218 evaltree(n->nbinary.ch1, EV_TESTED);
219 if (evalskip || exitstatus != 0) {
222 next = n->nbinary.ch2;
225 evaltree(n->nbinary.ch1, EV_TESTED);
226 if (evalskip || exitstatus == 0)
228 next = n->nbinary.ch2;
234 evalsubshell(n, flags);
235 do_etest = !(flags & EV_TESTED);
238 evalsubshell(n, flags);
241 evaltree(n->nif.test, EV_TESTED);
245 next = n->nif.ifpart;
246 else if (n->nif.elsepart)
247 next = n->nif.elsepart;
254 evalloop(n, flags & ~EV_EXIT);
257 evalfor(n, flags & ~EV_EXIT);
263 next = n->nclist.body;
266 if (n->nclist.body) {
267 evaltree(n->nclist.body, flags & ~EV_EXIT);
271 next = n->nclist.next;
274 defun(n->narg.text, n->narg.next);
278 evaltree(n->nnot.com, EV_TESTED);
279 exitstatus = !exitstatus;
284 do_etest = !(flags & EV_TESTED);
287 evalcommand(n, flags, NULL);
288 do_etest = !(flags & EV_TESTED);
291 out1fmt("Node type = %d\n", n->type);
300 if (eflag && exitstatus != 0 && do_etest)
301 exitshell(exitstatus);
308 evalloop(union node *n, int flags)
315 evaltree(n->nbinary.ch1, EV_TESTED);
317 skipping: if (evalskip == SKIPCONT && --skipcount <= 0) {
321 if (evalskip == SKIPBREAK && --skipcount <= 0)
323 if (evalskip == SKIPFUNC || evalskip == SKIPFILE)
327 if (n->type == NWHILE) {
334 evaltree(n->nbinary.ch2, flags);
346 evalfor(union node *n, int flags)
348 struct arglist arglist;
351 struct stackmark smark;
353 setstackmark(&smark);
354 arglist.lastp = &arglist.list;
355 for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
356 oexitstatus = exitstatus;
357 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
359 *arglist.lastp = NULL;
363 for (sp = arglist.list ; sp ; sp = sp->next) {
364 setvar(n->nfor.var, sp->text, 0);
365 evaltree(n->nfor.body, flags);
367 if (evalskip == SKIPCONT && --skipcount <= 0) {
371 if (evalskip == SKIPBREAK && --skipcount <= 0)
377 popstackmark(&smark);
382 * Evaluate a case statement, returning the selected tree.
384 * The exit status needs care to get right.
388 evalcase(union node *n)
392 struct arglist arglist;
393 struct stackmark smark;
395 setstackmark(&smark);
396 arglist.lastp = &arglist.list;
397 oexitstatus = exitstatus;
398 expandarg(n->ncase.expr, &arglist, EXP_TILDE);
399 for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
400 for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
401 if (casematch(patp, arglist.list->text)) {
402 popstackmark(&smark);
403 while (cp->nclist.next &&
404 cp->type == NCLISTFALLTHRU &&
405 cp->nclist.body == NULL)
406 cp = cp->nclist.next;
407 if (cp->nclist.next &&
408 cp->type == NCLISTFALLTHRU)
410 if (cp->nclist.body == NULL)
412 return (cp->nclist.body);
416 popstackmark(&smark);
424 * Kick off a subshell to evaluate a tree.
428 evalsubshell(union node *n, int flags)
431 int backgnd = (n->type == NBACKGND);
433 oexitstatus = exitstatus;
434 expredir(n->nredir.redirect);
435 if ((!backgnd && flags & EV_EXIT && !have_traps()) ||
436 forkshell(jp = makejob(n, 1), n, backgnd) == 0) {
439 redirect(n->nredir.redirect, 0);
440 evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */
441 } else if (!backgnd) {
443 exitstatus = waitforjob(jp, NULL);
451 * Evaluate a redirected compound command.
455 evalredir(union node *n, int flags)
457 struct jmploc jmploc;
458 struct jmploc *savehandler;
459 volatile int in_redirect = 1;
461 oexitstatus = exitstatus;
462 expredir(n->nredir.redirect);
463 savehandler = handler;
464 if (setjmp(jmploc.loc)) {
467 handler = savehandler;
470 if (e == EXERROR || e == EXEXEC) {
476 longjmp(handler->loc, 1);
480 redirect(n->nredir.redirect, REDIR_PUSH);
483 evaltree(n->nredir.n, flags);
486 handler = savehandler;
493 * Compute the names of the files in a redirection list.
497 expredir(union node *n)
501 for (redir = n ; redir ; redir = redir->nfile.next) {
504 switch (redir->type) {
510 expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
511 redir->nfile.expfname = fn.list->text;
515 if (redir->ndup.vname) {
516 expandarg(redir->ndup.vname, &fn, EXP_TILDE | EXP_REDIR);
517 fixredir(redir, fn.list->text, 1);
527 * Evaluate a pipeline. All the processes in the pipeline are children
528 * of the process creating the pipeline. (This differs from some versions
529 * of the shell, which make the last process in a pipeline the parent
534 evalpipe(union node *n)
542 TRACE(("evalpipe(%p) called\n", (void *)n));
544 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
547 jp = makejob(n, pipelen);
549 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
556 error("Pipe call failed: %s", strerror(errno));
559 if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
566 if (!(prevfd >= 0 && pip[0] == 0))
573 evaltree(lp->n, EV_EXIT);
582 if (n->npipe.backgnd == 0) {
584 exitstatus = waitforjob(jp, NULL);
585 TRACE(("evalpipe: job done exit status %d\n", exitstatus));
594 is_valid_fast_cmdsubst(union node *n)
597 return (n->type == NCMD);
601 * Execute a command inside back quotes. If it's a builtin command, we
602 * want to save its output in a block obtained from malloc. Otherwise
603 * we fork off a subprocess and get the output of the command via a pipe.
604 * Should be called with interrupts off.
608 evalbackcmd(union node *n, struct backcmd *result)
612 struct stackmark smark; /* unnecessary */
613 struct jmploc jmploc;
614 struct jmploc *savehandler;
615 struct localvar *savelocalvars;
617 setstackmark(&smark);
626 if (is_valid_fast_cmdsubst(n)) {
627 exitstatus = oexitstatus;
628 savelocalvars = localvars;
631 savehandler = handler;
632 if (setjmp(jmploc.loc)) {
633 if (exception == EXERROR || exception == EXEXEC)
635 else if (exception != 0) {
636 handler = savehandler;
639 localvars = savelocalvars;
640 longjmp(handler->loc, 1);
644 evalcommand(n, EV_BACKCMD, result);
646 handler = savehandler;
649 localvars = savelocalvars;
653 error("Pipe call failed: %s", strerror(errno));
655 if (forkshell(jp, n, FORK_NOJOB) == 0) {
662 evaltree(n, EV_EXIT);
669 popstackmark(&smark);
670 TRACE(("evalbackcmd done: fd=%d buf=%p nleft=%d jp=%p\n",
671 result->fd, result->buf, result->nleft, result->jp));
675 * Check if a builtin can safely be executed in the same process,
676 * even though it should be in a subshell (command substitution).
677 * Note that jobid, jobs, times and trap can show information not
678 * available in a child process; this is deliberate.
679 * The arguments should already have been expanded.
682 safe_builtin(int idx, int argc, char **argv)
684 if (idx == BLTINCMD || idx == COMMANDCMD || idx == ECHOCMD ||
685 idx == FALSECMD || idx == JOBIDCMD || idx == JOBSCMD ||
686 idx == KILLCMD || idx == PRINTFCMD || idx == PWDCMD ||
687 idx == TESTCMD || idx == TIMESCMD || idx == TRUECMD ||
690 if (idx == EXPORTCMD || idx == TRAPCMD || idx == ULIMITCMD ||
692 return (argc <= 1 || (argc == 2 && argv[1][0] == '-'));
694 return (argc <= 1 || (argc == 2 && (argv[1][0] == '-' ||
695 argv[1][0] == '+') && argv[1][1] == 'o' &&
696 argv[1][2] == '\0'));
701 * Execute a simple command.
702 * Note: This may or may not return if (flags & EV_EXIT).
706 evalcommand(union node *cmd, int flgs, struct backcmd *backcmd)
708 struct stackmark smark;
710 struct arglist arglist;
711 struct arglist varlist;
712 volatile int flags = flgs;
713 char **volatile argv;
720 struct cmdentry cmdentry;
721 struct job *volatile jp;
722 struct jmploc jmploc;
723 struct jmploc *savehandler;
724 const char *savecmdname;
725 struct shparam saveparam;
726 struct localvar *savelocalvars;
727 struct parsefile *savetopfile;
729 char *volatile lastarg;
731 volatile int do_clearcmdentry;
732 const char *path = pathval();
734 /* First expand the arguments. */
735 TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
736 setstackmark(&smark);
737 arglist.lastp = &arglist.list;
738 varlist.lastp = &varlist.list;
741 do_clearcmdentry = 0;
742 oexitstatus = exitstatus;
744 for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
745 if (varflag && isassignment(argp->narg.text)) {
746 expandarg(argp, &varlist, EXP_VARTILDE);
749 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
752 *arglist.lastp = NULL;
753 *varlist.lastp = NULL;
754 expredir(cmd->ncmd.redirect);
756 for (sp = arglist.list ; sp ; sp = sp->next)
758 /* Add one slot at the beginning for tryexec(). */
759 argv = stalloc(sizeof (char *) * (argc + 2));
762 for (sp = arglist.list ; sp ; sp = sp->next) {
763 TRACE(("evalcommand arg: %s\n", sp->text));
768 if (iflag && funcnest == 0 && argc > 0)
772 /* Print the command if xflag is set. */
776 ps4 = expandstr(ps4val());
777 out2str(ps4 != NULL ? ps4 : ps4val());
778 for (sp = varlist.list ; sp ; sp = sp->next) {
781 p = strchr(sp->text, '=');
784 outbin(sp->text, p - sp->text, out2);
790 for (sp = arglist.list ; sp ; sp = sp->next) {
793 /* Disambiguate command looking like assignment. */
794 if (sp == arglist.list &&
795 strchr(sp->text, '=') != NULL &&
796 strchr(sp->text, '\'') == NULL) {
808 /* Now locate the command. */
810 /* Variable assignment(s) without command */
811 cmdentry.cmdtype = CMDBUILTIN;
812 cmdentry.u.index = BLTINCMD;
813 cmdentry.special = 0;
815 static const char PATH[] = "PATH=";
816 int cmd_flags = 0, bltinonly = 0;
819 * Modify the command lookup path, if a PATH= assignment
822 for (sp = varlist.list ; sp ; sp = sp->next)
823 if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0) {
824 path = sp->text + sizeof(PATH) - 1;
826 * On `PATH=... command`, we need to make
827 * sure that the command isn't using the
828 * non-updated hash table of the outer PATH
829 * setting and we need to make sure that
830 * the hash table isn't filled with items
831 * from the temporary setting.
833 * It would be better to forbit using and
834 * updating the table while this command
835 * runs, by the command finding mechanism
836 * is heavily integrated with hash handling,
837 * so we just delete the hash before and after
838 * the command runs. Partly deleting like
839 * changepatch() does doesn't seem worth the
840 * bookinging effort, since most such runs add
841 * directories in front of the new PATH.
844 do_clearcmdentry = 1;
849 cmdentry.u.index = find_builtin(*argv, &cmdentry.special);
850 if (cmdentry.u.index < 0) {
851 cmdentry.u.index = BLTINCMD;
857 find_command(argv[0], &cmdentry, cmd_flags, path);
858 /* implement the bltin and command builtins here */
859 if (cmdentry.cmdtype != CMDBUILTIN)
861 if (cmdentry.u.index == BLTINCMD) {
867 } else if (cmdentry.u.index == COMMANDCMD) {
870 if (!strcmp(argv[1], "-p")) {
873 if (argv[2][0] == '-') {
874 if (strcmp(argv[2], "--"))
884 path = _PATH_STDPATH;
886 do_clearcmdentry = 1;
887 } else if (!strcmp(argv[1], "--")) {
892 } else if (argv[1][0] == '-')
898 cmd_flags |= DO_NOFUNC;
904 * Special builtins lose their special properties when
905 * called via 'command'.
907 if (cmd_flags & DO_NOFUNC)
908 cmdentry.special = 0;
911 /* Fork off a child process if necessary. */
912 if (((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
913 && ((flags & EV_EXIT) == 0 || have_traps()))
914 || ((flags & EV_BACKCMD) != 0
915 && (cmdentry.cmdtype != CMDBUILTIN ||
916 !safe_builtin(cmdentry.u.index, argc, argv)))) {
917 jp = makejob(cmd, 1);
919 if (flags & EV_BACKCMD) {
922 error("Pipe call failed: %s", strerror(errno));
924 if (forkshell(jp, cmd, mode) != 0)
925 goto parent; /* at end of routine */
926 if (flags & EV_BACKCMD) {
933 flags &= ~EV_BACKCMD;
938 /* This is the child process if a fork occurred. */
939 /* Execute the command. */
940 if (cmdentry.cmdtype == CMDFUNCTION) {
942 trputs("Shell function: "); trargs(argv);
944 saveparam = shellparam;
945 shellparam.malloc = 0;
946 shellparam.reset = 1;
947 shellparam.nparam = argc - 1;
948 shellparam.p = argv + 1;
949 shellparam.optnext = NULL;
951 savelocalvars = localvars;
953 reffunc(cmdentry.u.func);
954 savehandler = handler;
955 if (setjmp(jmploc.loc)) {
956 freeparam(&shellparam);
957 shellparam = saveparam;
959 unreffunc(cmdentry.u.func);
961 localvars = savelocalvars;
963 handler = savehandler;
964 longjmp(handler->loc, 1);
968 redirect(cmd->ncmd.redirect, REDIR_PUSH);
970 for (sp = varlist.list ; sp ; sp = sp->next)
972 exitstatus = oexitstatus;
973 evaltree(getfuncnode(cmdentry.u.func),
974 flags & (EV_TESTED | EV_EXIT));
976 unreffunc(cmdentry.u.func);
978 localvars = savelocalvars;
979 freeparam(&shellparam);
980 shellparam = saveparam;
981 handler = savehandler;
985 if (evalskip == SKIPFUNC) {
990 exitshell(exitstatus);
991 } else if (cmdentry.cmdtype == CMDBUILTIN) {
993 trputs("builtin command: "); trargs(argv);
995 mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
996 if (flags == EV_BACKCMD) {
998 memout.nextc = memout.buf;
1000 mode |= REDIR_BACKQ;
1002 savecmdname = commandname;
1003 savetopfile = getcurrentfile();
1004 cmdenviron = varlist.list;
1006 savehandler = handler;
1007 if (setjmp(jmploc.loc)) {
1010 exitstatus = SIGINT+128;
1011 else if (e != EXEXIT)
1016 redirect(cmd->ncmd.redirect, mode);
1018 * If there is no command word, redirection errors should
1019 * not be fatal but assignment errors should.
1022 cmdentry.special = 1;
1023 listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET);
1026 commandname = argv[0];
1028 nextopt_optptr = NULL; /* initialize nextopt */
1029 builtin_flags = flags;
1030 exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
1039 handler = savehandler;
1040 commandname = savecmdname;
1042 exitshell(exitstatus);
1043 if (flags == EV_BACKCMD) {
1044 backcmd->buf = memout.buf;
1045 backcmd->nleft = memout.nextc - memout.buf;
1048 if (cmdentry.u.index != EXECCMD)
1051 if ((e != EXERROR && e != EXEXEC)
1052 || cmdentry.special)
1054 popfilesupto(savetopfile);
1055 if (flags != EV_BACKCMD)
1060 trputs("normal command: "); trargs(argv);
1062 redirect(cmd->ncmd.redirect, 0);
1063 for (sp = varlist.list ; sp ; sp = sp->next)
1064 setvareq(sp->text, VEXPORT|VSTACK);
1065 envp = environment();
1066 shellexec(argv, envp, path, cmdentry.u.index);
1071 parent: /* parent process gets here (if we forked) */
1072 if (mode == FORK_FG) { /* argument to fork */
1074 exitstatus = waitforjob(jp, &realstatus);
1076 if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) {
1077 evalskip = SKIPBREAK;
1078 skipcount = loopnest;
1080 } else if (mode == FORK_NOJOB) {
1081 backcmd->fd = pip[0];
1088 setvar("_", lastarg, 0);
1089 if (do_clearcmdentry)
1091 popstackmark(&smark);
1097 * Search for a command. This is called before we fork so that the
1098 * location of the command will be available in the parent as well as
1099 * the child. The check for "goodname" is an overly conservative
1100 * check that the name will not be subject to expansion.
1104 prehash(union node *n)
1106 struct cmdentry entry;
1108 if (n && n->type == NCMD && n->ncmd.args)
1109 if (goodname(n->ncmd.args->narg.text))
1110 find_command(n->ncmd.args->narg.text, &entry, 0,
1117 * Builtin commands. Builtin commands whose functions are closely
1118 * tied to evaluation are implemented here.
1122 * No command given, a bltin command with no arguments, or a bltin command
1123 * with an invalid name.
1127 bltincmd(int argc, char **argv)
1130 out2fmt_flush("%s: not found\n", argv[1]);
1134 * Preserve exitstatus of a previous possible redirection
1142 * Handle break and continue commands. Break, continue, and return are
1143 * all handled by setting the evalskip flag. The evaluation routines
1144 * above all check this flag, and if it is set they start skipping
1145 * commands rather than executing them. The variable skipcount is
1146 * the number of loops to break/continue, or the number of function
1147 * levels to return. (The latter is always 1.) It should probably
1148 * be an error to break out of more loops than exist, but it isn't
1149 * in the standard shell so we don't make it one here.
1153 breakcmd(int argc, char **argv)
1155 int n = argc > 1 ? number(argv[1]) : 1;
1160 evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
1167 * The `command' command.
1170 commandcmd(int argc, char **argv)
1176 path = bltinlookup("PATH", 1);
1178 optind = optreset = 1;
1180 while ((ch = getopt(argc, argv, "pvV")) != -1) {
1183 path = _PATH_STDPATH;
1186 cmd = TYPECMD_SMALLV;
1193 error("unknown option: -%c", optopt);
1201 error("wrong number of arguments");
1202 return typecmd_impl(2, argv - 1, cmd, path);
1205 error("commandcmd bad call");
1208 * Do nothing successfully if no command was specified;
1209 * ksh also does this.
1216 * The return command.
1220 returncmd(int argc, char **argv)
1222 int ret = argc > 1 ? number(argv[1]) : oexitstatus;
1225 evalskip = SKIPFUNC;
1228 /* skip the rest of the file */
1229 evalskip = SKIPFILE;
1237 falsecmd(int argc __unused, char **argv __unused)
1244 truecmd(int argc __unused, char **argv __unused)
1251 execcmd(int argc, char **argv)
1254 * Because we have historically not supported any options,
1255 * only treat "--" specially.
1257 if (argc > 1 && strcmp(argv[1], "--") == 0)
1262 iflag = 0; /* exit on error */
1265 for (sp = cmdenviron; sp ; sp = sp->next)
1266 setvareq(sp->text, VEXPORT|VSTACK);
1267 shellexec(argv + 1, environment(), pathval(), 0);
1275 timescmd(int argc __unused, char **argv __unused)
1278 long shumins, shsmins, chumins, chsmins;
1279 double shusecs, shssecs, chusecs, chssecs;
1281 if (getrusage(RUSAGE_SELF, &ru) < 0)
1283 shumins = ru.ru_utime.tv_sec / 60;
1284 shusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1285 shsmins = ru.ru_stime.tv_sec / 60;
1286 shssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1287 if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
1289 chumins = ru.ru_utime.tv_sec / 60;
1290 chusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1291 chsmins = ru.ru_stime.tv_sec / 60;
1292 chssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1293 out1fmt("%ldm%.3fs %ldm%.3fs\n%ldm%.3fs %ldm%.3fs\n", shumins,
1294 shusecs, shsmins, shssecs, chumins, chusecs, chsmins, chssecs);