From bd9024b4d748fdf8b2fdc9b4c5cf222eea49fa8d Mon Sep 17 00:00:00 2001 From: tjr Date: Sun, 21 Jul 2002 06:49:14 +0000 Subject: Implement the P1003.2 `command' builtin command, which is used to suppress shell function and alias lookup. The -p option has been implemented, the UPE -v and -V options have not. The old `command' command has been renamed to `builtin'. --- bin/sh/eval.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'bin/sh/eval.c') diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 5d8f309..4e1079b 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95"; #include __FBSDID("$FreeBSD$"); +#include #include #include #include /* For WIFSIGNALED(status) */ @@ -747,7 +748,9 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) && (cmdentry.cmdtype != CMDBUILTIN || cmdentry.u.index == CDCMD || cmdentry.u.index == DOTCMD - || cmdentry.u.index == EVALCMD))) { + || cmdentry.u.index == EVALCMD)) + || (cmdentry.cmdtype == CMDBUILTIN && + cmdentry.u.index == COMMANDCMD)) { jp = makejob(cmd, 1); mode = cmd->ncmd.backgnd; if (flags & EV_BACKCMD) { @@ -869,7 +872,8 @@ cmddone: #ifndef NO_HISTORY || cmdentry.u.index == HISTCMD #endif - || cmdentry.u.index == EXECCMD) + || cmdentry.u.index == EXECCMD + || cmdentry.u.index == COMMANDCMD) exraise(e); FORCEINTON; } @@ -986,6 +990,54 @@ breakcmd(int argc, char **argv) return 0; } +/* + * The `command' command. + */ +int +commandcmd(int argc, char **argv) +{ + static char stdpath[] = _PATH_STDPATH; + struct jmploc loc, *old; + struct strlist *sp; + char *path; + int ch; + + for (sp = cmdenviron; sp ; sp = sp->next) + setvareq(sp->text, VEXPORT|VSTACK); + path = pathval(); + + optind = optreset = 1; + while ((ch = getopt(argc, argv, "p")) != -1) { + switch (ch) { + case 'p': + path = stdpath; + break; + case '?': + default: + error("unknown option: -%c", optopt); + } + } + argc -= optind; + argv += optind; + + if (argc != 0) { + old = handler; + handler = &loc; + if (setjmp(handler->loc) == 0) + shellexec(argv, environment(), path, 0); + handler = old; + if (exception == EXEXEC) + exit(exerrno); + exraise(exception); + } + + /* + * Do nothing successfully if no command was specified; + * ksh also does this. + */ + exit(0); +} + /* * The return command. -- cgit v1.1