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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
38 #include <sys/cdefs.h>
43 #include <sys/resource.h>
70 #include "myhistedit.h"
74 int evalskip; /* set if we are skipping commands */
75 int skipcount; /* number of levels to skip */
76 static int loopnest; /* current loop nesting level */
77 int funcnest; /* depth of function calls */
78 static int builtin_flags; /* evalcommand flags for builtins */
82 struct arglist *cmdenviron;
83 int exitstatus; /* exit status of last command */
84 int oexitstatus; /* saved exit status */
87 static void evalloop(union node *, int);
88 static void evalfor(union node *, int);
89 static union node *evalcase(union node *);
90 static void evalsubshell(union node *, int);
91 static void evalredir(union node *, int);
92 static void exphere(union node *, struct arglist *);
93 static void expredir(union node *);
94 static void evalpipe(union node *);
95 static int is_valid_fast_cmdsubst(union node *n);
96 static void evalcommand(union node *, int, struct backcmd *);
97 static void prehash(union node *);
101 * Called to reset things after an exception.
117 evalcmd(int argc, char **argv)
126 STARTSTACKSTR(concat);
130 if ((p = *ap++) == NULL)
134 STPUTC('\0', concat);
135 p = grabstackstr(concat);
137 evalstring(p, builtin_flags);
145 * Execute a command or commands contained in a string.
149 evalstring(const char *s, int flags)
152 struct stackmark smark;
156 flags_exit = flags & EV_EXIT;
159 setstackmark(&smark);
160 setinputstring(s, 1);
161 while ((n = parsecmd(0)) != NEOF) {
162 if (n != NULL && !nflag) {
163 if (flags_exit && preadateof())
164 evaltree(n, flags | EV_EXIT);
171 popstackmark(&smark);
172 setstackmark(&smark);
175 popstackmark(&smark);
184 * Evaluate a parse tree. The value is left in the global variable
189 evaltree(union node *n, int flags)
193 struct stackmark smark;
195 setstackmark(&smark);
198 TRACE(("evaltree(NULL) called\n"));
205 displayhist = 1; /* show history substitutions done with fc */
207 TRACE(("evaltree(%p: %d) called\n", (void *)n, n->type));
210 evaltree(n->nbinary.ch1, flags & ~EV_EXIT);
213 next = n->nbinary.ch2;
216 evaltree(n->nbinary.ch1, EV_TESTED);
217 if (evalskip || exitstatus != 0) {
220 next = n->nbinary.ch2;
223 evaltree(n->nbinary.ch1, EV_TESTED);
224 if (evalskip || exitstatus == 0)
226 next = n->nbinary.ch2;
232 evalsubshell(n, flags);
233 do_etest = !(flags & EV_TESTED);
236 evalsubshell(n, flags);
239 evaltree(n->nif.test, EV_TESTED);
243 next = n->nif.ifpart;
244 else if (n->nif.elsepart)
245 next = n->nif.elsepart;
252 evalloop(n, flags & ~EV_EXIT);
255 evalfor(n, flags & ~EV_EXIT);
261 next = n->nclist.body;
264 if (n->nclist.body) {
265 evaltree(n->nclist.body, flags & ~EV_EXIT);
269 next = n->nclist.next;
272 defun(n->narg.text, n->narg.next);
276 evaltree(n->nnot.com, EV_TESTED);
279 exitstatus = !exitstatus;
284 do_etest = !(flags & EV_TESTED);
287 evalcommand(n, flags, (struct backcmd *)NULL);
288 do_etest = !(flags & EV_TESTED);
291 out1fmt("Node type = %d\n", n->type);
296 popstackmark(&smark);
297 setstackmark(&smark);
300 popstackmark(&smark);
303 if (eflag && exitstatus != 0 && do_etest)
304 exitshell(exitstatus);
311 evalloop(union node *n, int flags)
319 evaltree(n->nbinary.ch1, EV_TESTED);
321 if (evalskip == SKIPCONT && --skipcount <= 0) {
325 if (evalskip == SKIPBREAK && --skipcount <= 0)
327 if (evalskip == SKIPRETURN)
331 if (n->type == NWHILE) {
338 evaltree(n->nbinary.ch2, flags);
348 evalfor(union node *n, int flags)
350 struct arglist arglist;
355 emptyarglist(&arglist);
356 for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
357 oexitstatus = exitstatus;
358 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
363 for (i = 0; i < arglist.count; i++) {
364 setvar(n->nfor.var, arglist.args[i], 0);
365 evaltree(n->nfor.body, flags);
368 if (evalskip == SKIPCONT && --skipcount <= 0) {
372 if (evalskip == SKIPBREAK && --skipcount <= 0)
383 * Evaluate a case statement, returning the selected tree.
385 * The exit status needs care to get right.
389 evalcase(union node *n)
393 struct arglist arglist;
395 emptyarglist(&arglist);
396 oexitstatus = exitstatus;
397 expandarg(n->ncase.expr, &arglist, EXP_TILDE);
398 for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
399 for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
400 if (casematch(patp, arglist.args[0])) {
401 while (cp->nclist.next &&
402 cp->type == NCLISTFALLTHRU &&
403 cp->nclist.body == NULL)
404 cp = cp->nclist.next;
405 if (cp->nclist.next &&
406 cp->type == NCLISTFALLTHRU)
408 if (cp->nclist.body == NULL)
410 return (cp->nclist.body);
421 * Kick off a subshell to evaluate a tree.
425 evalsubshell(union node *n, int flags)
428 int backgnd = (n->type == NBACKGND);
430 oexitstatus = exitstatus;
431 expredir(n->nredir.redirect);
432 if ((!backgnd && flags & EV_EXIT && !have_traps()) ||
433 forkshell(jp = makejob(n, 1), n, backgnd) == 0) {
436 redirect(n->nredir.redirect, 0);
437 evaltree(n->nredir.n, flags | EV_EXIT); /* never returns */
438 } else if (! backgnd) {
440 exitstatus = waitforjob(jp, (int *)NULL);
448 * Evaluate a redirected compound command.
452 evalredir(union node *n, int flags)
454 struct jmploc jmploc;
455 struct jmploc *savehandler;
456 volatile int in_redirect = 1;
458 oexitstatus = exitstatus;
459 expredir(n->nredir.redirect);
460 savehandler = handler;
461 if (setjmp(jmploc.loc)) {
464 handler = savehandler;
467 if (e == EXERROR && in_redirect) {
471 longjmp(handler->loc, 1);
475 redirect(n->nredir.redirect, REDIR_PUSH);
478 evaltree(n->nredir.n, flags);
481 handler = savehandler;
488 exphere(union node *redir, struct arglist *fn)
490 struct jmploc jmploc;
491 struct jmploc *savehandler;
492 struct localvar *savelocalvars;
493 int need_longjmp = 0;
494 unsigned char saveoptreset;
496 redir->nhere.expdoc = "";
497 savelocalvars = localvars;
499 saveoptreset = shellparam.reset;
501 savehandler = handler;
502 if (setjmp(jmploc.loc))
503 need_longjmp = exception != EXERROR;
506 expandarg(redir->nhere.doc, fn, 0);
507 redir->nhere.expdoc = fn->args[0];
510 handler = savehandler;
513 localvars = savelocalvars;
514 shellparam.reset = saveoptreset;
516 longjmp(handler->loc, 1);
522 * Compute the names of the files in a redirection list.
526 expredir(union node *n)
530 for (redir = n ; redir ; redir = redir->nfile.next) {
533 switch (redir->type) {
539 expandarg(redir->nfile.fname, &fn, EXP_TILDE);
540 redir->nfile.expfname = fn.args[0];
544 if (redir->ndup.vname) {
545 expandarg(redir->ndup.vname, &fn, EXP_TILDE);
546 fixredir(redir, fn.args[0], 1);
559 * Evaluate a pipeline. All the processes in the pipeline are children
560 * of the process creating the pipeline. (This differs from some versions
561 * of the shell, which make the last process in a pipeline the parent
566 evalpipe(union node *n)
574 TRACE(("evalpipe(%p) called\n", (void *)n));
576 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
579 jp = makejob(n, pipelen);
581 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
588 error("Pipe call failed: %s", strerror(errno));
591 if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
598 if (!(prevfd >= 0 && pip[0] == 0))
605 evaltree(lp->n, EV_EXIT);
614 if (n->npipe.backgnd == 0) {
616 exitstatus = waitforjob(jp, (int *)NULL);
617 TRACE(("evalpipe: job done exit status %d\n", exitstatus));
626 is_valid_fast_cmdsubst(union node *n)
629 return (n->type == NCMD);
633 * Execute a command inside back quotes. If it's a builtin command, we
634 * want to save its output in a block obtained from malloc. Otherwise
635 * we fork off a subprocess and get the output of the command via a pipe.
636 * Should be called with interrupts off.
640 evalbackcmd(union node *n, struct backcmd *result)
644 struct stackmark smark;
645 struct jmploc jmploc;
646 struct jmploc *savehandler;
647 struct localvar *savelocalvars;
648 unsigned char saveoptreset;
658 setstackmark(&smark);
659 exitstatus = oexitstatus;
660 if (is_valid_fast_cmdsubst(n)) {
661 savelocalvars = localvars;
663 saveoptreset = shellparam.reset;
665 savehandler = handler;
666 if (setjmp(jmploc.loc)) {
667 if (exception == EXERROR)
669 else if (exception != 0) {
670 handler = savehandler;
673 localvars = savelocalvars;
674 shellparam.reset = saveoptreset;
675 longjmp(handler->loc, 1);
679 evalcommand(n, EV_BACKCMD, result);
681 handler = savehandler;
684 localvars = savelocalvars;
685 shellparam.reset = saveoptreset;
688 error("Pipe call failed: %s", strerror(errno));
690 if (forkshell(jp, n, FORK_NOJOB) == 0) {
697 evaltree(n, EV_EXIT);
703 popstackmark(&smark);
704 TRACE(("evalbackcmd done: fd=%d buf=%p nleft=%d jp=%p\n",
705 result->fd, result->buf, result->nleft, result->jp));
709 mustexpandto(const char *argtext, const char *mask)
712 if (*argtext == CTLQUOTEMARK || *argtext == CTLQUOTEEND) {
716 if (*argtext == CTLESC)
718 else if (BASESYNTAX[(int)*argtext] == CCTL)
720 if (*argtext != *mask)
722 if (*argtext == '\0')
730 isdeclarationcmd(struct narg *arg)
732 int have_command = 0;
736 while (mustexpandto(arg->text, "command")) {
738 arg = &arg->next->narg;
742 * To also allow "command -p" and "command --" as part of
743 * a declaration command, add code here.
744 * We do not do this, as ksh does not do it either and it
745 * is not required by POSIX.
748 return (mustexpandto(arg->text, "export") ||
749 mustexpandto(arg->text, "readonly") ||
750 (mustexpandto(arg->text, "local") &&
751 (have_command || !isfunc("local"))));
755 xtracecommand(struct arglist *varlist, int argc, char **argv)
758 const char *text, *p, *ps4;
761 ps4 = expandstr(ps4val());
762 out2str(ps4 != NULL ? ps4 : ps4val());
763 for (i = 0; i < varlist->count; i++) {
764 text = varlist->args[i];
767 p = strchr(text, '=');
770 outbin(text, p - text, out2);
776 for (i = 0; i < argc; i++) {
788 * Check if a builtin can safely be executed in the same process,
789 * even though it should be in a subshell (command substitution).
790 * Note that jobid, jobs, times and trap can show information not
791 * available in a child process; this is deliberate.
792 * The arguments should already have been expanded.
795 safe_builtin(int idx, int argc, char **argv)
797 /* Generated from builtins.def. */
798 if (safe_builtin_always(idx))
800 if (idx == EXPORTCMD || idx == TRAPCMD || idx == ULIMITCMD ||
802 return (argc <= 1 || (argc == 2 && argv[1][0] == '-'));
804 return (argc <= 1 || (argc == 2 && (argv[1][0] == '-' ||
805 argv[1][0] == '+') && argv[1][1] == 'o' &&
806 argv[1][2] == '\0'));
811 * Execute a simple command.
812 * Note: This may or may not return if (flags & EV_EXIT).
816 evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
819 struct arglist arglist;
820 struct arglist varlist;
827 struct cmdentry cmdentry;
829 struct jmploc jmploc;
830 struct jmploc *savehandler;
832 struct shparam saveparam;
833 struct localvar *savelocalvars;
834 struct parsefile *savetopfile;
838 int do_clearcmdentry;
839 const char *path = pathval();
842 /* First expand the arguments. */
843 TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
844 emptyarglist(&arglist);
845 emptyarglist(&varlist);
848 do_clearcmdentry = 0;
849 oexitstatus = exitstatus;
851 /* Add one slot at the beginning for tryexec(). */
852 appendarglist(&arglist, nullstr);
853 for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
854 if (varflag && isassignment(argp->narg.text)) {
855 expandarg(argp, varflag == 1 ? &varlist : &arglist,
858 } else if (varflag == 1)
859 varflag = isdeclarationcmd(&argp->narg) ? 2 : 0;
860 expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
862 appendarglist(&arglist, nullstr);
863 expredir(cmd->ncmd.redirect);
864 argc = arglist.count - 2;
865 argv = &arglist.args[1];
869 if (iflag && funcnest == 0 && argc > 0)
870 lastarg = argv[argc - 1];
872 /* Print the command if xflag is set. */
874 xtracecommand(&varlist, argc, argv);
876 /* Now locate the command. */
878 /* Variable assignment(s) without command */
879 cmdentry.cmdtype = CMDBUILTIN;
880 cmdentry.u.index = BLTINCMD;
881 cmdentry.special = 0;
883 static const char PATH[] = "PATH=";
884 int cmd_flags = 0, bltinonly = 0;
887 * Modify the command lookup path, if a PATH= assignment
890 for (i = 0; i < varlist.count; i++)
891 if (strncmp(varlist.args[i], PATH, sizeof(PATH) - 1) == 0) {
892 path = varlist.args[i] + sizeof(PATH) - 1;
894 * On `PATH=... command`, we need to make
895 * sure that the command isn't using the
896 * non-updated hash table of the outer PATH
897 * setting and we need to make sure that
898 * the hash table isn't filled with items
899 * from the temporary setting.
901 * It would be better to forbid using and
902 * updating the table while this command
903 * runs, by the command finding mechanism
904 * is heavily integrated with hash handling,
905 * so we just delete the hash before and after
906 * the command runs. Partly deleting like
907 * changepatch() does doesn't seem worth the
908 * bookinging effort, since most such runs add
909 * directories in front of the new PATH.
912 do_clearcmdentry = 1;
917 cmdentry.u.index = find_builtin(*argv, &cmdentry.special);
918 if (cmdentry.u.index < 0) {
919 cmdentry.u.index = BLTINCMD;
925 find_command(argv[0], &cmdentry, cmd_flags, path);
926 /* implement the bltin and command builtins here */
927 if (cmdentry.cmdtype != CMDBUILTIN)
929 if (cmdentry.u.index == BLTINCMD) {
935 } else if (cmdentry.u.index == COMMANDCMD) {
938 if (!strcmp(argv[1], "-p")) {
941 if (argv[2][0] == '-') {
942 if (strcmp(argv[2], "--"))
952 path = _PATH_STDPATH;
954 do_clearcmdentry = 1;
955 } else if (!strcmp(argv[1], "--")) {
960 } else if (argv[1][0] == '-')
966 cmd_flags |= DO_NOFUNC;
972 * Special builtins lose their special properties when
973 * called via 'command'.
975 if (cmd_flags & DO_NOFUNC)
976 cmdentry.special = 0;
979 /* Fork off a child process if necessary. */
980 if (((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
981 && ((flags & EV_EXIT) == 0 || have_traps()))
982 || ((flags & EV_BACKCMD) != 0
983 && (cmdentry.cmdtype != CMDBUILTIN ||
984 !safe_builtin(cmdentry.u.index, argc, argv)))) {
985 jp = makejob(cmd, 1);
987 if (flags & EV_BACKCMD) {
990 error("Pipe call failed: %s", strerror(errno));
992 if (cmdentry.cmdtype == CMDNORMAL &&
993 cmd->ncmd.redirect == NULL &&
994 varlist.count == 0 &&
995 (mode == FORK_FG || mode == FORK_NOJOB) &&
996 !disvforkset() && !iflag && !mflag) {
997 vforkexecshell(jp, argv, environment(), path,
998 cmdentry.u.index, flags & EV_BACKCMD ? pip : NULL);
1001 if (forkshell(jp, cmd, mode) != 0)
1002 goto parent; /* at end of routine */
1003 if (flags & EV_BACKCMD) {
1010 flags &= ~EV_BACKCMD;
1015 /* This is the child process if a fork occurred. */
1016 /* Execute the command. */
1017 if (cmdentry.cmdtype == CMDFUNCTION) {
1019 trputs("Shell function: "); trargs(argv);
1021 saveparam = shellparam;
1022 shellparam.malloc = 0;
1023 shellparam.reset = 1;
1024 shellparam.nparam = argc - 1;
1025 shellparam.p = argv + 1;
1026 shellparam.optp = NULL;
1027 shellparam.optnext = NULL;
1029 savelocalvars = localvars;
1031 reffunc(cmdentry.u.func);
1032 savehandler = handler;
1033 if (setjmp(jmploc.loc)) {
1035 unreffunc(cmdentry.u.func);
1037 localvars = savelocalvars;
1038 freeparam(&shellparam);
1039 shellparam = saveparam;
1041 handler = savehandler;
1042 longjmp(handler->loc, 1);
1046 redirect(cmd->ncmd.redirect, REDIR_PUSH);
1048 for (i = 0; i < varlist.count; i++)
1049 mklocal(varlist.args[i]);
1050 exitstatus = oexitstatus;
1051 evaltree(getfuncnode(cmdentry.u.func),
1052 flags & (EV_TESTED | EV_EXIT));
1054 unreffunc(cmdentry.u.func);
1056 localvars = savelocalvars;
1057 freeparam(&shellparam);
1058 shellparam = saveparam;
1059 handler = savehandler;
1063 if (evalskip == SKIPRETURN) {
1068 exitshell(exitstatus);
1069 } else if (cmdentry.cmdtype == CMDBUILTIN) {
1071 trputs("builtin command: "); trargs(argv);
1073 mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
1074 if (flags == EV_BACKCMD) {
1075 memout.nextc = memout.buf;
1076 mode |= REDIR_BACKQ;
1078 savecmdname = commandname;
1079 savetopfile = getcurrentfile();
1080 cmdenviron = &varlist;
1082 savehandler = handler;
1083 if (setjmp(jmploc.loc)) {
1086 exitstatus = SIGINT+128;
1090 redirect(cmd->ncmd.redirect, mode);
1091 outclearerror(out1);
1093 * If there is no command word, redirection errors should
1094 * not be fatal but assignment errors should.
1097 cmdentry.special = 1;
1098 listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET);
1101 commandname = argv[0];
1103 nextopt_optptr = NULL; /* initialize nextopt */
1104 builtin_flags = flags;
1105 exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
1107 if (outiserror(out1)) {
1108 warning("write error on stdout");
1109 if (exitstatus == 0 || exitstatus == 1)
1119 handler = savehandler;
1120 commandname = savecmdname;
1122 exitshell(exitstatus);
1123 if (flags == EV_BACKCMD) {
1124 backcmd->buf = memout.buf;
1125 backcmd->nleft = memout.buf != NULL ?
1126 memout.nextc - memout.buf : 0;
1128 memout.nextc = NULL;
1129 memout.bufend = NULL;
1130 memout.bufsize = 64;
1132 if (cmdentry.u.index != EXECCMD)
1135 if (e != EXERROR || cmdentry.special)
1137 popfilesupto(savetopfile);
1138 if (flags != EV_BACKCMD)
1143 trputs("normal command: "); trargs(argv);
1145 redirect(cmd->ncmd.redirect, 0);
1146 for (i = 0; i < varlist.count; i++)
1147 setvareq(varlist.args[i], VEXPORT|VSTACK);
1148 envp = environment();
1149 shellexec(argv, envp, path, cmdentry.u.index);
1154 parent: /* parent process gets here (if we forked) */
1155 if (mode == FORK_FG) { /* argument to fork */
1157 exitstatus = waitforjob(jp, &signaled);
1159 if (iflag && loopnest > 0 && signaled) {
1160 evalskip = SKIPBREAK;
1161 skipcount = loopnest;
1163 } else if (mode == FORK_NOJOB) {
1164 backcmd->fd = pip[0];
1171 setvar("_", lastarg, 0);
1172 if (do_clearcmdentry)
1179 * Search for a command. This is called before we fork so that the
1180 * location of the command will be available in the parent as well as
1181 * the child. The check for "goodname" is an overly conservative
1182 * check that the name will not be subject to expansion.
1186 prehash(union node *n)
1188 struct cmdentry entry;
1190 if (n && n->type == NCMD && n->ncmd.args)
1191 if (goodname(n->ncmd.args->narg.text))
1192 find_command(n->ncmd.args->narg.text, &entry, 0,
1199 * Builtin commands. Builtin commands whose functions are closely
1200 * tied to evaluation are implemented here.
1204 * No command given, a bltin command with no arguments, or a bltin command
1205 * with an invalid name.
1209 bltincmd(int argc, char **argv)
1212 out2fmt_flush("%s: not found\n", argv[1]);
1216 * Preserve exitstatus of a previous possible command substitution
1224 * Handle break and continue commands. Break, continue, and return are
1225 * all handled by setting the evalskip flag. The evaluation routines
1226 * above all check this flag, and if it is set they start skipping
1227 * commands rather than executing them. The variable skipcount is
1228 * the number of loops to break/continue, or the number of function
1229 * levels to return. (The latter is always 1.) It should probably
1230 * be an error to break out of more loops than exist, but it isn't
1231 * in the standard shell so we don't make it one here.
1235 breakcmd(int argc, char **argv)
1241 /* Allow arbitrarily large numbers. */
1242 n = strtol(argv[1], &end, 10);
1243 if (!is_digit(argv[1][0]) || *end != '\0')
1244 error("Illegal number: %s", argv[1]);
1250 evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
1257 * The `command' command.
1260 commandcmd(int argc __unused, char **argv __unused)
1266 path = bltinlookup("PATH", 1);
1268 while ((ch = nextopt("pvV")) != '\0') {
1271 path = _PATH_STDPATH;
1274 cmd = TYPECMD_SMALLV;
1283 if (*argptr == NULL || argptr[1] != NULL)
1284 error("wrong number of arguments");
1285 return typecmd_impl(2, argptr - 1, cmd, path);
1287 if (*argptr != NULL)
1288 error("commandcmd bad call");
1291 * Do nothing successfully if no command was specified;
1292 * ksh also does this.
1299 * The return command.
1303 returncmd(int argc, char **argv)
1305 int ret = argc > 1 ? number(argv[1]) : oexitstatus;
1307 evalskip = SKIPRETURN;
1314 falsecmd(int argc __unused, char **argv __unused)
1321 truecmd(int argc __unused, char **argv __unused)
1328 execcmd(int argc, char **argv)
1333 * Because we have historically not supported any options,
1334 * only treat "--" specially.
1336 if (argc > 1 && strcmp(argv[1], "--") == 0)
1339 iflag = 0; /* exit on error */
1342 for (i = 0; i < cmdenviron->count; i++)
1343 setvareq(cmdenviron->args[i], VEXPORT|VSTACK);
1344 shellexec(argv + 1, environment(), pathval(), 0);
1352 timescmd(int argc __unused, char **argv __unused)
1355 long shumins, shsmins, chumins, chsmins;
1356 double shusecs, shssecs, chusecs, chssecs;
1358 if (getrusage(RUSAGE_SELF, &ru) < 0)
1360 shumins = ru.ru_utime.tv_sec / 60;
1361 shusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1362 shsmins = ru.ru_stime.tv_sec / 60;
1363 shssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1364 if (getrusage(RUSAGE_CHILDREN, &ru) < 0)
1366 chumins = ru.ru_utime.tv_sec / 60;
1367 chusecs = ru.ru_utime.tv_sec % 60 + ru.ru_utime.tv_usec / 1000000.;
1368 chsmins = ru.ru_stime.tv_sec / 60;
1369 chssecs = ru.ru_stime.tv_sec % 60 + ru.ru_stime.tv_usec / 1000000.;
1370 out1fmt("%ldm%.3fs %ldm%.3fs\n%ldm%.3fs %ldm%.3fs\n", shumins,
1371 shusecs, shsmins, shssecs, chumins, chusecs, chsmins, chssecs);