1 /* $NetBSD: exec.c,v 1.37 2003/08/07 09:05:31 agc Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #ifdef HAVE_SYS_CDEFS_H
36 #include <sys/cdefs.h>
40 static char sccsid
[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
42 __RCSID("$NetBSD: exec.c,v 1.37 2003/08/07 09:05:31 agc Exp $");
46 #include <sys/types.h>
56 * When commands are first encountered, they are entered in a hash table.
57 * This ensures that a full path search will not have to be done for them
60 * We should investigate converting to a linear search, even though that
61 * would make the command name "hash" a misnomer.
84 #ifdef __INNOTEK_LIBC__
85 #include <InnoTekLIBC/backend.h>
89 #define CMDTABLESIZE 31 /* should be prime */
90 #define ARB 1 /* actual size determined at run time */
95 struct tblentry
*next
; /* next entry in hash chain */
96 union param param
; /* definition of builtin function */
97 short cmdtype
; /* index identifying command */
98 char rehash
; /* if set, cd done since entry created */
99 char cmdname
[ARB
]; /* name of command */
103 STATIC
struct tblentry
*cmdtable
[CMDTABLESIZE
];
104 STATIC
int builtinloc
= -1; /* index in path of %builtin, or -1 */
105 int exerrno
= 0; /* Last exec error */
108 STATIC
void tryexec(char *, char **, char **, int, int);
109 STATIC
void execinterp(char **, char **);
110 STATIC
void printentry(struct tblentry
*, int);
111 STATIC
void clearcmdentry(int);
112 STATIC
struct tblentry
*cmdlookup(const char *, int);
113 STATIC
void delete_cmd_entry(void);
115 STATIC
int stat_pc_exec_exts(char *fullname
, struct stat
*st
, int has_ext
);
119 extern char *const parsekwd
[];
122 * Exec a program. Never returns. If you change this routine, you may
123 * have to change the find_command routine as well.
127 shellexec(char **argv
, char **envp
, const char *path
, int idx
, int vforked
)
132 int has_ext
= strlen(argv
[0]) - 4;
133 has_ext
= has_ext
> 0
134 && argv
[0][has_ext
] == '.'
135 /* use strstr and upper/lower permuated extensions to avoid multiple strcasecmp calls. */
136 && strstr("exe;" "Exe;" "EXe;" "EXE;" "ExE;" "eXe;" "eXE;" "exE;"
137 "cmd;" "Cmd;" "CMd;" "CMD;" "CmD;" "cMd;" "cMD;" "cmD;"
138 "com;" "Com;" "COm;" "COM;" "CoM;" "cOm;" "cOM;" "coM;"
139 "bat;" "Bat;" "BAt;" "BAT;" "BaT;" "bAt;" "bAT;" "baT;"
140 "btm;" "Btm;" "BTm;" "BTM;" "BtM;" "bTm;" "bTM;" "btM;",
141 argv
[0] + has_ext
+ 1)
144 const int has_ext
= 1;
146 TRACE(("shellexec: argv[0]=%s idx=%d\n", argv
[0], idx
));
147 if (strchr(argv
[0], '/') != NULL
) {
148 cmdname
= stalloc(strlen(argv
[0]) + 5);
149 strcpy(cmdname
, argv
[0]);
150 tryexec(cmdname
, argv
, envp
, vforked
, has_ext
);
151 TRACE(("shellexec: cmdname=%s\n", cmdname
));
156 while ((cmdname
= padvance(&path
, argv
[0])) != NULL
) {
157 if (--idx
< 0 && pathopt
== NULL
) {
158 tryexec(cmdname
, argv
, envp
, vforked
, has_ext
);
159 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
166 /* Map to POSIX errors */
178 TRACE(("shellexec failed for '%s', errno %d, vforked %d, suppressint %d\n",
179 argv
[0], e
, vforked
, suppressint
));
180 exerror(EXEXEC
, "%s: %s", argv
[0], errmsg(e
, E_EXEC
));
186 tryexec(char *cmd
, char **argv
, char **envp
, int vforked
, int has_ext
)
189 #ifdef EXEC_HASH_BANG_SCRIPT
193 /* exploit the effect of stat_pc_exec_exts which adds the
194 * correct extentions to the file.
198 stat_pc_exec_exts(cmd
, &st
, 0);
200 #if defined __INNOTEK_LIBC__ && defined EXEC_HASH_BANG_SCRIPT
201 __libc_Back_gfProcessHandleHashBangScripts
= 0;
206 execve(cmd
, argv
, envp
);
207 } while (errno
== EINTR
);
209 execve(cmd
, argv
, envp
);
214 /* We are currently vfork(2)ed, so raise an
215 * exception, and evalcommand will try again
216 * with a normal fork(2).
218 exraise(EXSHELLPROC
);
221 setinputfile(cmd
, 0);
222 commandname
= arg0
= savestr(argv
[0]);
223 #ifdef EXEC_HASH_BANG_SCRIPT
224 pgetc(); pungetc(); /* fill up input buffer */
226 if (parsenleft
> 2 && p
[0] == '#' && p
[1] == '!') {
228 execinterp(argv
, envp
);
232 exraise(EXSHELLPROC
);
238 #ifdef EXEC_HASH_BANG_SCRIPT
240 * Execute an interpreter introduced by "#!", for systems where this
241 * feature has not been built into the kernel. If the interpreter is
242 * the shell, return (effectively ignoring the "#!"). If the execution
243 * of the interpreter fails, exit.
245 * This code peeks inside the input buffer in order to avoid actually
246 * reading any input. It would benefit from a rewrite.
252 execinterp(char **argv
, char **envp
)
260 char *newargs
[NEWARGS
];
266 inp
= parsenextc
+ 2;
269 while (--n
>= 0 && (*inp
== ' ' || *inp
== '\t'))
273 if ((c
= *inp
++) == '\n')
275 if (ap
== &newargs
[NEWARGS
])
276 bad
: error("Bad #! line");
280 } while (--n
>= 0 && (c
= *inp
++) != ' ' && c
!= '\t' && c
!= '\n');
283 *ap
++ = grabstackstr(outp
);
285 if (ap
== newargs
+ 1) { /* if no args, maybe no exec is needed */
288 if (equal(p
, "sh") || equal(p
, "ash")) {
289 TRACE(("hash bang self\n"));
301 i
= (char *)ap
- (char *)newargs
; /* size in bytes */
303 error("Bad #! line");
304 for (ap2
= argv
; *ap2
++ != NULL
; );
305 new = ckmalloc(i
+ ((char *)ap2
- (char *)argv
));
306 ap
= newargs
, ap2
= new;
307 while ((i
-= sizeof (char **)) >= 0)
310 while (*ap2
++ = *ap
++);
311 TRACE(("hash bang '%s'\n", new[0]));
312 shellexec(new, envp
, pathval(), 0, 0);
320 * Do a path search. The variable path (passed by reference) should be
321 * set to the start of the path before the first call; padvance will update
322 * this value as it proceeds. Successive calls to padvance will return
323 * the possible path expansions in sequence. If an option (indicated by
324 * a percent sign) appears in the path entry then the global variable
325 * pathopt will be set to point to it; otherwise pathopt will be set to
332 padvance(const char **path
, const char *name
)
346 for (p
= start
; *p
&& *p
!= ';' && *p
!= '%' ; p
++);
348 for (p
= start
; *p
&& *p
!= ':' && *p
!= '%' ; p
++);
350 len
= p
- start
+ strlen(name
) + 2; /* "2" is for '/' and '\0' */
352 len
+= 4; /* "4" is for .exe/.com/.cmd/.bat/.btm */
354 while (stackblocksize() < len
)
361 memcpy(q
, start
, p
- start
);
367 while ((s
= strchr(s
, '\\')) != NULL
)
374 while (*p
&& *p
!= ';') p
++;
376 while (*p
&& *p
!= ':') p
++;
392 STATIC
int stat_pc_exec_exts(char *fullname
, struct stat
*st
, int has_ext
)
394 /* skip the SYSV crap */
395 if (stat(fullname
, st
) >= 0)
397 if (!has_ext
&& errno
== ENOENT
)
399 char *psz
= strchr(fullname
, '\0');
400 memcpy(psz
, ".exe", 5);
401 if (stat(fullname
, st
) >= 0)
403 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
406 memcpy(psz
, ".cmd", 5);
407 if (stat(fullname
, st
) >= 0)
409 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
412 memcpy(psz
, ".bat", 5);
413 if (stat(fullname
, st
) >= 0)
415 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
418 memcpy(psz
, ".com", 5);
419 if (stat(fullname
, st
) >= 0)
421 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
424 memcpy(psz
, ".btm", 5);
425 if (stat(fullname
, st
) >= 0)
431 #endif /* PC_EXE_EXTS */
435 /*** Command hashing code ***/
439 hashcmd(int argc
, char **argv
)
441 struct tblentry
**pp
;
442 struct tblentry
*cmdp
;
445 struct cmdentry entry
;
449 while ((c
= nextopt("rv")) != '\0') {
452 } else if (c
== 'v') {
456 if (*argptr
== NULL
) {
457 for (pp
= cmdtable
; pp
< &cmdtable
[CMDTABLESIZE
] ; pp
++) {
458 for (cmdp
= *pp
; cmdp
; cmdp
= cmdp
->next
) {
459 if (verbose
|| cmdp
->cmdtype
== CMDNORMAL
)
460 printentry(cmdp
, verbose
);
465 while ((name
= *argptr
) != NULL
) {
466 if ((cmdp
= cmdlookup(name
, 0)) != NULL
467 && (cmdp
->cmdtype
== CMDNORMAL
468 || (cmdp
->cmdtype
== CMDBUILTIN
&& builtinloc
>= 0)))
470 find_command(name
, &entry
, DO_ERR
, pathval());
472 if (entry
.cmdtype
!= CMDUNKNOWN
) { /* if no error msg */
473 cmdp
= cmdlookup(name
, 0);
474 printentry(cmdp
, verbose
);
485 printentry(struct tblentry
*cmdp
, int verbose
)
491 switch (cmdp
->cmdtype
) {
493 idx
= cmdp
->param
.index
;
496 name
= padvance(&path
, cmdp
->cmdname
);
498 } while (--idx
>= 0);
502 out1fmt("special builtin %s", cmdp
->cmdname
);
505 out1fmt("builtin %s", cmdp
->cmdname
);
508 out1fmt("function %s", cmdp
->cmdname
);
512 commandtext(&ps
, cmdp
->param
.func
);
520 error("internal error: %s cmdtype %d", cmdp
->cmdname
, cmdp
->cmdtype
);
530 * Resolve a command name. If you change this routine, you may have to
531 * change the shellexec routine as well.
535 find_command(char *name
, struct cmdentry
*entry
, int act
, const char *path
)
537 struct tblentry
*cmdp
, loc_cmd
;
543 int (*bltin
)(int,char **);
546 int has_ext
= strlen(name
) - 4;
547 has_ext
= has_ext
> 0
548 && name
[has_ext
] == '.'
549 /* use strstr and upper/lower permuated extensions to avoid multiple strcasecmp calls. */
550 && strstr("exe;" "Exe;" "EXe;" "EXE;" "ExE;" "eXe;" "eXE;" "exE;"
551 "cmd;" "Cmd;" "CMd;" "CMD;" "CmD;" "cMd;" "cMD;" "cmD;"
552 "com;" "Com;" "COm;" "COM;" "CoM;" "cOm;" "cOM;" "coM;"
553 "bat;" "Bat;" "BAt;" "BAT;" "BaT;" "bAt;" "bAT;" "baT;"
554 "btm;" "Btm;" "BTm;" "BTM;" "BtM;" "bTm;" "bTM;" "btM;",
559 /* If name contains a slash, don't use PATH or hash table */
560 if (strchr(name
, '/') != NULL
) {
562 while (stat(name
, &statb
) < 0) {
567 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
569 entry
->cmdtype
= CMDUNKNOWN
;
573 entry
->cmdtype
= CMDNORMAL
;
577 entry
->cmdtype
= CMDNORMAL
;
582 if (path
!= pathval())
585 if (act
& DO_ALTPATH
&& strstr(path
, "%builtin") != NULL
)
588 /* If name is in the table, check answer will be ok */
589 if ((cmdp
= cmdlookup(name
, 0)) != NULL
) {
591 switch (cmdp
->cmdtype
) {
593 if (act
& DO_ALTPATH
) {
599 if (act
& DO_NOFUNC
) {
605 if ((act
& DO_ALTBLTIN
) || builtinloc
>= 0) {
611 /* if not invalidated by cd, we're done */
612 if (cmdp
->rehash
== 0)
617 /* If %builtin not in path, check for builtin next */
618 if ((act
& DO_ALTPATH
? !(act
& DO_ALTBLTIN
) : builtinloc
< 0) &&
619 (bltin
= find_builtin(name
)) != 0)
620 goto builtin_success
;
622 /* We have to search path. */
623 prev
= -1; /* where to start */
624 if (cmdp
) { /* doing a rehash */
625 if (cmdp
->cmdtype
== CMDBUILTIN
)
628 prev
= cmdp
->param
.index
;
634 while ((fullname
= padvance(&path
, name
)) != NULL
) {
638 if (prefix("builtin", pathopt
)) {
639 if ((bltin
= find_builtin(name
)) == 0)
641 goto builtin_success
;
642 } else if (prefix("func", pathopt
)) {
645 /* ignore unimplemented options */
649 /* if rehash, don't redo absolute path names */
650 if (fullname
[0] == '/' && idx
<= prev
) {
653 TRACE(("searchexec \"%s\": no change\n", name
));
657 while (stat_pc_exec_exts(fullname
, &statb
, has_ext
) < 0) {
659 while (stat(fullname
, &statb
) < 0) {
665 if (errno
!= ENOENT
&& errno
!= ENOTDIR
)
670 e
= EACCES
; /* if we fail, this will be the error */
671 if (!S_ISREG(statb
.st_mode
))
673 if (pathopt
) { /* this is a %func directory */
676 stalloc(strlen(fullname
) + 1);
677 readcmdfile(fullname
);
678 if ((cmdp
= cmdlookup(name
, 0)) == NULL
||
679 cmdp
->cmdtype
!= CMDFUNCTION
)
680 error("%s not defined in %s", name
, fullname
);
685 /* XXX this code stops root executing stuff, and is buggy
686 if you need a group from the group list. */
687 if (statb
.st_uid
== geteuid()) {
688 if ((statb
.st_mode
& 0100) == 0)
690 } else if (statb
.st_gid
== getegid()) {
691 if ((statb
.st_mode
& 010) == 0)
694 if ((statb
.st_mode
& 01) == 0)
698 TRACE(("searchexec \"%s\" returns \"%s\"\n", name
, fullname
));
700 if (act
& DO_ALTPATH
) {
701 stalloc(strlen(fullname
) + 1);
704 cmdp
= cmdlookup(name
, 1);
705 cmdp
->cmdtype
= CMDNORMAL
;
706 cmdp
->param
.index
= idx
;
711 /* We failed. If there was an entry for this command, delete it */
715 outfmt(out2
, "%s: %s\n", name
, errmsg(e
, E_EXEC
));
716 entry
->cmdtype
= CMDUNKNOWN
;
721 if (act
& DO_ALTPATH
)
724 cmdp
= cmdlookup(name
, 1);
725 if (cmdp
->cmdtype
== CMDFUNCTION
)
726 /* DO_NOFUNC must have been set */
728 cmdp
->cmdtype
= CMDBUILTIN
;
729 cmdp
->param
.bltin
= bltin
;
733 entry
->cmdtype
= cmdp
->cmdtype
;
734 entry
->u
= cmdp
->param
;
740 * Search the table of builtin commands.
744 (*find_builtin(name
))(int, char **)
747 const struct builtincmd
*bp
;
749 for (bp
= builtincmd
; bp
->name
; bp
++) {
750 if (*bp
->name
== *name
&& equal(bp
->name
, name
))
757 (*find_splbltin(name
))(int, char **)
760 const struct builtincmd
*bp
;
762 for (bp
= splbltincmd
; bp
->name
; bp
++) {
763 if (*bp
->name
== *name
&& equal(bp
->name
, name
))
770 * At shell startup put special builtins into hash table.
771 * ensures they are executed first (see posix).
772 * We stop functions being added with the same name
773 * (as they are impossible to call)
777 hash_special_builtins(void)
779 const struct builtincmd
*bp
;
780 struct tblentry
*cmdp
;
782 for (bp
= splbltincmd
; bp
->name
; bp
++) {
783 cmdp
= cmdlookup(bp
->name
, 1);
784 cmdp
->cmdtype
= CMDSPLBLTIN
;
785 cmdp
->param
.bltin
= bp
->builtin
;
792 * Called when a cd is done. Marks all commands so the next time they
793 * are executed they will be rehashed.
799 struct tblentry
**pp
;
800 struct tblentry
*cmdp
;
802 for (pp
= cmdtable
; pp
< &cmdtable
[CMDTABLESIZE
] ; pp
++) {
803 for (cmdp
= *pp
; cmdp
; cmdp
= cmdp
->next
) {
804 if (cmdp
->cmdtype
== CMDNORMAL
805 || (cmdp
->cmdtype
== CMDBUILTIN
&& builtinloc
>= 0))
814 * Fix command hash table when PATH changed.
815 * Called before PATH is changed. The argument is the new value of PATH;
816 * pathval() still returns the old value at this point.
817 * Called with interrupts off.
821 changepath(const char *newval
)
823 const char *old
, *new;
830 firstchange
= 9999; /* assume no change */
837 if ((*old
== '\0' && *new == ';')
838 || (*old
== ';' && *new == '\0'))
840 if ((*old
== '\0' && *new == ':')
841 || (*old
== ':' && *new == '\0'))
844 old
= new; /* ignore subsequent differences */
848 if (*new == '%' && bltin
< 0 && prefix("builtin", new + 1))
859 if (builtinloc
< 0 && bltin
>= 0)
860 builtinloc
= bltin
; /* zap builtins */
861 if (builtinloc
>= 0 && bltin
< 0)
863 clearcmdentry(firstchange
);
869 * Clear out command entries. The argument specifies the first entry in
870 * PATH which has changed.
874 clearcmdentry(int firstchange
)
876 struct tblentry
**tblp
;
877 struct tblentry
**pp
;
878 struct tblentry
*cmdp
;
881 for (tblp
= cmdtable
; tblp
< &cmdtable
[CMDTABLESIZE
] ; tblp
++) {
883 while ((cmdp
= *pp
) != NULL
) {
884 if ((cmdp
->cmdtype
== CMDNORMAL
&&
885 cmdp
->param
.index
>= firstchange
)
886 || (cmdp
->cmdtype
== CMDBUILTIN
&&
887 builtinloc
>= firstchange
)) {
900 * Delete all functions.
904 MKINIT
void deletefuncs(void);
905 MKINIT
void hash_special_builtins(void);
908 hash_special_builtins();
919 struct tblentry
**tblp
;
920 struct tblentry
**pp
;
921 struct tblentry
*cmdp
;
924 for (tblp
= cmdtable
; tblp
< &cmdtable
[CMDTABLESIZE
] ; tblp
++) {
926 while ((cmdp
= *pp
) != NULL
) {
927 if (cmdp
->cmdtype
== CMDFUNCTION
) {
929 freefunc(cmdp
->param
.func
);
942 * Locate a command in the command hash table. If "add" is nonzero,
943 * add the command to the table if it is not already present. The
944 * variable "lastcmdentry" is set to point to the address of the link
945 * pointing to the entry, so that delete_cmd_entry can delete the
949 struct tblentry
**lastcmdentry
;
952 STATIC
struct tblentry
*
953 cmdlookup(const char *name
, int add
)
957 struct tblentry
*cmdp
;
958 struct tblentry
**pp
;
965 pp
= &cmdtable
[hashval
% CMDTABLESIZE
];
966 for (cmdp
= *pp
; cmdp
; cmdp
= cmdp
->next
) {
967 if (equal(cmdp
->cmdname
, name
))
971 if (add
&& cmdp
== NULL
) {
973 cmdp
= *pp
= ckmalloc(sizeof (struct tblentry
) - ARB
976 cmdp
->cmdtype
= CMDUNKNOWN
;
978 strcpy(cmdp
->cmdname
, name
);
986 * Delete the command entry returned on the last lookup.
990 delete_cmd_entry(void)
992 struct tblentry
*cmdp
;
995 cmdp
= *lastcmdentry
;
996 *lastcmdentry
= cmdp
->next
;
1005 getcmdentry(char *name
, struct cmdentry
*entry
)
1007 struct tblentry
*cmdp
= cmdlookup(name
, 0);
1010 entry
->u
= cmdp
->param
;
1011 entry
->cmdtype
= cmdp
->cmdtype
;
1013 entry
->cmdtype
= CMDUNKNOWN
;
1021 * Add a new command entry, replacing any existing command entry for
1022 * the same name - except special builtins.
1026 addcmdentry(char *name
, struct cmdentry
*entry
)
1028 struct tblentry
*cmdp
;
1031 cmdp
= cmdlookup(name
, 1);
1032 if (cmdp
->cmdtype
!= CMDSPLBLTIN
) {
1033 if (cmdp
->cmdtype
== CMDFUNCTION
) {
1034 freefunc(cmdp
->param
.func
);
1036 cmdp
->cmdtype
= entry
->cmdtype
;
1037 cmdp
->param
= entry
->u
;
1044 * Define a shell function.
1048 defun(char *name
, union node
*func
)
1050 struct cmdentry entry
;
1053 entry
.cmdtype
= CMDFUNCTION
;
1054 entry
.u
.func
= copyfunc(func
);
1055 addcmdentry(name
, &entry
);
1061 * Delete a function if it exists.
1065 unsetfunc(char *name
)
1067 struct tblentry
*cmdp
;
1069 if ((cmdp
= cmdlookup(name
, 0)) != NULL
&&
1070 cmdp
->cmdtype
== CMDFUNCTION
) {
1071 freefunc(cmdp
->param
.func
);
1079 * Locate and print what a word is...
1080 * also used for 'command -[v|V]'
1084 typecmd(int argc
, char **argv
)
1086 struct cmdentry entry
;
1087 struct tblentry
*cmdp
;
1097 while ((c
= nextopt("vVp")) != 0) {
1099 case 'v': v_flag
= 1; break;
1100 case 'V': V_flag
= 1; break;
1101 case 'p': p_flag
= 1; break;
1105 if (p_flag
&& (v_flag
|| V_flag
))
1106 error("cannot specify -p with -v or -V");
1108 while ((arg
= *argptr
++)) {
1111 /* First look at the keywords */
1112 for (pp
= parsekwd
; *pp
; pp
++)
1113 if (**pp
== *arg
&& equal(*pp
, arg
))
1120 out1str(" is a shell keyword\n");
1124 /* Then look at the aliases */
1125 if ((ap
= lookupalias(arg
, 1)) != NULL
) {
1127 out1fmt(" is an alias for \n");
1128 out1fmt("%s\n", ap
->val
);
1132 /* Then check if it is a tracked alias */
1133 if ((cmdp
= cmdlookup(arg
, 0)) != NULL
) {
1134 entry
.cmdtype
= cmdp
->cmdtype
;
1135 entry
.u
= cmdp
->param
;
1137 /* Finally use brute force */
1138 find_command(arg
, &entry
, DO_ABS
, pathval());
1141 switch (entry
.cmdtype
) {
1143 if (strchr(arg
, '/') == NULL
) {
1144 const char *path
= pathval();
1146 int j
= entry
.u
.index
;
1148 name
= padvance(&path
, arg
);
1153 cmdp
? " a tracked alias for" : "");
1154 out1fmt("%s\n", name
);
1156 if (access(arg
, X_OK
) == 0) {
1159 out1fmt("%s\n", arg
);
1172 out1str(" is a shell function\n");
1174 out1fmt("%s\n", arg
);
1179 out1str(" is a shell builtin\n");
1181 out1fmt("%s\n", arg
);
1186 out1str(" is a special shell builtin\n");
1188 out1fmt("%s\n", arg
);
1193 out1str(": not found\n");