Index: head/bin/sh/cd.c =================================================================== --- head/bin/sh/cd.c (revision 336319) +++ head/bin/sh/cd.c (revision 336320) @@ -1,430 +1,430 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include /* * The cd and pwd commands. */ #include "shell.h" #include "var.h" #include "nodes.h" /* for jobs.h */ #include "jobs.h" #include "options.h" #include "output.h" #include "memalloc.h" #include "error.h" #include "exec.h" #include "redir.h" #include "mystring.h" #include "show.h" #include "cd.h" #include "builtins.h" static int cdlogical(char *); static int cdphysical(char *); static int docd(char *, int, int); static char *getcomponent(char **); static char *findcwd(char *); static void updatepwd(char *); static char *getpwd(void); static char *getpwd2(void); static char *curdir = NULL; /* current working directory */ int cdcmd(int argc __unused, char **argv __unused) { const char *dest; const char *path; char *p; struct stat statb; int ch, phys, print = 0, getcwderr = 0; int rc; int errno1 = ENOENT; phys = Pflag; while ((ch = nextopt("eLP")) != '\0') { switch (ch) { case 'e': getcwderr = 1; break; case 'L': phys = 0; break; case 'P': phys = 1; break; } } if (*argptr != NULL && argptr[1] != NULL) error("too many arguments"); if ((dest = *argptr) == NULL && (dest = bltinlookup("HOME", 1)) == NULL) error("HOME not set"); if (*dest == '\0') dest = "."; if (dest[0] == '-' && dest[1] == '\0') { dest = bltinlookup("OLDPWD", 1); if (dest == NULL) error("OLDPWD not set"); print = 1; } if (dest[0] == '/' || (dest[0] == '.' && (dest[1] == '/' || dest[1] == '\0')) || (dest[0] == '.' && dest[1] == '.' && (dest[2] == '/' || dest[2] == '\0')) || (path = bltinlookup("CDPATH", 1)) == NULL) path = ""; - while ((p = padvance(&path, dest)) != NULL) { + while ((p = padvance(&path, NULL, dest)) != NULL) { if (stat(p, &statb) < 0) { if (errno != ENOENT) errno1 = errno; } else if (!S_ISDIR(statb.st_mode)) errno1 = ENOTDIR; else { if (!print) { /* * XXX - rethink */ if (p[0] == '.' && p[1] == '/' && p[2] != '\0') print = strcmp(p + 2, dest); else print = strcmp(p, dest); } rc = docd(p, print, phys); if (rc >= 0) return getcwderr ? rc : 0; if (errno != ENOENT) errno1 = errno; } } error("%s: %s", dest, strerror(errno1)); /*NOTREACHED*/ return 0; } /* * Actually change the directory. In an interactive shell, print the * directory name if "print" is nonzero. */ static int docd(char *dest, int print, int phys) { int rc; TRACE(("docd(\"%s\", %d, %d) called\n", dest, print, phys)); /* If logical cd fails, fall back to physical. */ if ((phys || (rc = cdlogical(dest)) < 0) && (rc = cdphysical(dest)) < 0) return (-1); if (print && iflag && curdir) { out1fmt("%s\n", curdir); /* * Ignore write errors to preserve the invariant that the * current directory is changed iff the exit status is 0 * (or 1 if -e was given and the full pathname could not be * determined). */ flushout(out1); outclearerror(out1); } return (rc); } static int cdlogical(char *dest) { char *p; char *q; char *component; char *path; struct stat statb; int first; int badstat; /* * Check each component of the path. If we find a symlink or * something we can't stat, clear curdir to force a getcwd() * next time we get the value of the current directory. */ badstat = 0; path = stsavestr(dest); STARTSTACKSTR(p); if (*dest == '/') { STPUTC('/', p); path++; } first = 1; while ((q = getcomponent(&path)) != NULL) { if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0')) continue; if (! first) STPUTC('/', p); first = 0; component = q; STPUTS(q, p); if (equal(component, "..")) continue; STACKSTRNUL(p); if (lstat(stackblock(), &statb) < 0) { badstat = 1; break; } } INTOFF; if ((p = findcwd(badstat ? NULL : dest)) == NULL || chdir(p) < 0) { INTON; return (-1); } updatepwd(p); INTON; return (0); } static int cdphysical(char *dest) { char *p; int rc = 0; INTOFF; if (chdir(dest) < 0) { INTON; return (-1); } p = findcwd(NULL); if (p == NULL) { warning("warning: failed to get name of current directory"); rc = 1; } updatepwd(p); INTON; return (rc); } /* * Get the next component of the path name pointed to by *path. * This routine overwrites *path and the string pointed to by it. */ static char * getcomponent(char **path) { char *p; char *start; if ((p = *path) == NULL) return NULL; start = *path; while (*p != '/' && *p != '\0') p++; if (*p == '\0') { *path = NULL; } else { *p++ = '\0'; *path = p; } return start; } static char * findcwd(char *dir) { char *new; char *p; char *path; /* * If our argument is NULL, we don't know the current directory * any more because we traversed a symbolic link or something * we couldn't stat(). */ if (dir == NULL || curdir == NULL) return getpwd2(); path = stsavestr(dir); STARTSTACKSTR(new); if (*dir != '/') { STPUTS(curdir, new); if (STTOPC(new) == '/') STUNPUTC(new); } while ((p = getcomponent(&path)) != NULL) { if (equal(p, "..")) { while (new > stackblock() && (STUNPUTC(new), *new) != '/'); } else if (*p != '\0' && ! equal(p, ".")) { STPUTC('/', new); STPUTS(p, new); } } if (new == stackblock()) STPUTC('/', new); STACKSTRNUL(new); return stackblock(); } /* * Update curdir (the name of the current directory) in response to a * cd command. We also call hashcd to let the routines in exec.c know * that the current directory has changed. */ static void updatepwd(char *dir) { char *prevdir; hashcd(); /* update command hash table */ setvar("PWD", dir, VEXPORT); setvar("OLDPWD", curdir, VEXPORT); prevdir = curdir; curdir = dir ? savestr(dir) : NULL; ckfree(prevdir); } int pwdcmd(int argc __unused, char **argv __unused) { char *p; int ch, phys; phys = Pflag; while ((ch = nextopt("LP")) != '\0') { switch (ch) { case 'L': phys = 0; break; case 'P': phys = 1; break; } } if (*argptr != NULL) error("too many arguments"); if (!phys && getpwd()) { out1str(curdir); out1c('\n'); } else { if ((p = getpwd2()) == NULL) error(".: %s", strerror(errno)); out1str(p); out1c('\n'); } return 0; } /* * Get the current directory and cache the result in curdir. */ static char * getpwd(void) { char *p; if (curdir) return curdir; p = getpwd2(); if (p != NULL) curdir = savestr(p); return curdir; } #define MAXPWD 256 /* * Return the current directory. */ static char * getpwd2(void) { char *pwd; int i; for (i = MAXPWD;; i *= 2) { pwd = stalloc(i); if (getcwd(pwd, i) != NULL) return pwd; stunalloc(pwd); if (errno != ERANGE) break; } return NULL; } /* * Initialize PWD in a new shell. * If the shell is interactive, we need to warn if this fails. */ void pwd_init(int warn) { char *pwd; struct stat stdot, stpwd; pwd = lookupvar("PWD"); if (pwd && *pwd == '/' && stat(".", &stdot) != -1 && stat(pwd, &stpwd) != -1 && stdot.st_dev == stpwd.st_dev && stdot.st_ino == stpwd.st_ino) { if (curdir) ckfree(curdir); curdir = savestr(pwd); } if (getpwd() == NULL && warn) out2fmt_flush("sh: cannot determine working directory\n"); setvar("PWD", curdir, VEXPORT); } Index: head/bin/sh/exec.c =================================================================== --- head/bin/sh/exec.c (revision 336319) +++ head/bin/sh/exec.c (revision 336320) @@ -1,776 +1,784 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include /* * When commands are first encountered, they are entered in a hash table. * This ensures that a full path search will not have to be done for them * on each invocation. * * We should investigate converting to a linear search, even though that * would make the command name "hash" a misnomer. */ #include "shell.h" #include "main.h" #include "nodes.h" #include "parser.h" #include "redir.h" #include "eval.h" #include "exec.h" #include "builtins.h" #include "var.h" #include "options.h" #include "input.h" #include "output.h" #include "syntax.h" #include "memalloc.h" #include "error.h" #include "mystring.h" #include "show.h" #include "jobs.h" #include "alias.h" #define CMDTABLESIZE 31 /* should be prime */ struct tblentry { struct tblentry *next; /* next entry in hash chain */ union param param; /* definition of builtin function */ int special; /* flag for special builtin commands */ signed char cmdtype; /* index identifying command */ char cmdname[]; /* name of command */ }; static struct tblentry *cmdtable[CMDTABLESIZE]; static int cmdtable_cd = 0; /* cmdtable contains cd-dependent entries */ int exerrno = 0; /* Last exec error */ static void tryexec(char *, char **, char **); static void printentry(struct tblentry *, int); static struct tblentry *cmdlookup(const char *, int); static void delete_cmd_entry(void); static void addcmdentry(const char *, struct cmdentry *); /* * Exec a program. Never returns. If you change this routine, you may * have to change the find_command routine as well. * * The argv array may be changed and element argv[-1] should be writable. */ void shellexec(char **argv, char **envp, const char *path, int idx) { char *cmdname; + const char *opt; int e; if (strchr(argv[0], '/') != NULL) { tryexec(argv[0], argv, envp); e = errno; } else { e = ENOENT; - while ((cmdname = padvance(&path, argv[0])) != NULL) { - if (--idx < 0 && pathopt == NULL) { + while ((cmdname = padvance(&path, &opt, argv[0])) != NULL) { + if (--idx < 0 && opt == NULL) { tryexec(cmdname, argv, envp); if (errno != ENOENT && errno != ENOTDIR) e = errno; if (e == ENOEXEC) break; } stunalloc(cmdname); } } /* Map to POSIX errors */ if (e == ENOENT || e == ENOTDIR) { exerrno = 127; exerror(EXEXEC, "%s: not found", argv[0]); } else { exerrno = 126; exerror(EXEXEC, "%s: %s", argv[0], strerror(e)); } } static void tryexec(char *cmd, char **argv, char **envp) { int e, in; ssize_t n; char buf[256]; execve(cmd, argv, envp); e = errno; if (e == ENOEXEC) { INTOFF; in = open(cmd, O_RDONLY | O_NONBLOCK); if (in != -1) { n = pread(in, buf, sizeof buf, 0); close(in); if (n > 0 && memchr(buf, '\0', n) != NULL) { errno = ENOEXEC; return; } } *argv = cmd; *--argv = __DECONST(char *, _PATH_BSHELL); execve(_PATH_BSHELL, argv, envp); } errno = e; } /* * Do a path search. The variable path (passed by reference) should be * set to the start of the path before the first call; padvance will update * this value as it proceeds. Successive calls to padvance will return - * the possible path expansions in sequence. If an option (indicated by - * a percent sign) appears in the path entry then the global variable - * pathopt will be set to point to it; otherwise pathopt will be set to - * NULL. + * the possible path expansions in sequence. If popt is not NULL, options + * are processed: if an option (indicated by a percent sign) appears in + * the path entry then *popt will be set to point to it; else *popt will be + * set to NULL. If popt is NULL, percent signs are not special. */ -const char *pathopt; - char * -padvance(const char **path, const char *name) +padvance(const char **path, const char **popt, const char *name) { const char *p, *start; char *q; size_t len, namelen; if (*path == NULL) return NULL; start = *path; - for (p = start; *p && *p != ':' && *p != '%'; p++) - ; /* nothing */ + if (popt != NULL) + for (p = start; *p && *p != ':' && *p != '%'; p++) + ; /* nothing */ + else + for (p = start; *p && *p != ':'; p++) + ; /* nothing */ namelen = strlen(name); len = p - start + namelen + 2; /* "2" is for '/' and '\0' */ STARTSTACKSTR(q); CHECKSTRSPACE(len, q); if (p != start) { memcpy(q, start, p - start); q += p - start; *q++ = '/'; } memcpy(q, name, namelen + 1); - pathopt = NULL; - if (*p == '%') { - pathopt = ++p; - while (*p && *p != ':') p++; + if (popt != NULL) { + if (*p == '%') { + *popt = ++p; + while (*p && *p != ':') p++; + } else + *popt = NULL; } if (*p == ':') *path = p + 1; else *path = NULL; return stalloc(len); } /*** Command hashing code ***/ int hashcmd(int argc __unused, char **argv __unused) { struct tblentry **pp; struct tblentry *cmdp; int c; int verbose; struct cmdentry entry; char *name; int errors; errors = 0; verbose = 0; while ((c = nextopt("rv")) != '\0') { if (c == 'r') { clearcmdentry(); } else if (c == 'v') { verbose++; } } if (*argptr == NULL) { for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) { for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) { if (cmdp->cmdtype == CMDNORMAL) printentry(cmdp, verbose); } } return 0; } while ((name = *argptr) != NULL) { if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->cmdtype == CMDNORMAL) delete_cmd_entry(); find_command(name, &entry, DO_ERR, pathval()); if (entry.cmdtype == CMDUNKNOWN) errors = 1; else if (verbose) { cmdp = cmdlookup(name, 0); if (cmdp != NULL) printentry(cmdp, verbose); else { outfmt(out2, "%s: not found\n", name); errors = 1; } flushall(); } argptr++; } return errors; } static void printentry(struct tblentry *cmdp, int verbose) { int idx; - const char *path; + const char *path, *opt; char *name; if (cmdp->cmdtype == CMDNORMAL) { idx = cmdp->param.index; path = pathval(); do { - name = padvance(&path, cmdp->cmdname); + name = padvance(&path, &opt, cmdp->cmdname); stunalloc(name); } while (--idx >= 0); out1str(name); } else if (cmdp->cmdtype == CMDBUILTIN) { out1fmt("builtin %s", cmdp->cmdname); } else if (cmdp->cmdtype == CMDFUNCTION) { out1fmt("function %s", cmdp->cmdname); if (verbose) { INTOFF; name = commandtext(getfuncnode(cmdp->param.func)); out1c(' '); out1str(name); ckfree(name); INTON; } #ifdef DEBUG } else { error("internal error: cmdtype %d", cmdp->cmdtype); #endif } out1c('\n'); } /* * Resolve a command name. If you change this routine, you may have to * change the shellexec routine as well. */ void find_command(const char *name, struct cmdentry *entry, int act, const char *path) { struct tblentry *cmdp, loc_cmd; int idx; + const char *opt; char *fullname; struct stat statb; int e; int i; int spec; int cd; /* If name contains a slash, don't use the hash table */ if (strchr(name, '/') != NULL) { entry->cmdtype = CMDNORMAL; entry->u.index = 0; entry->special = 0; return; } cd = 0; /* If name is in the table, we're done */ if ((cmdp = cmdlookup(name, 0)) != NULL) { if (cmdp->cmdtype == CMDFUNCTION && act & DO_NOFUNC) cmdp = NULL; else goto success; } /* Check for builtin next */ if ((i = find_builtin(name, &spec)) >= 0) { INTOFF; cmdp = cmdlookup(name, 1); if (cmdp->cmdtype == CMDFUNCTION) cmdp = &loc_cmd; cmdp->cmdtype = CMDBUILTIN; cmdp->param.index = i; cmdp->special = spec; INTON; goto success; } /* We have to search path. */ e = ENOENT; idx = -1; - for (;(fullname = padvance(&path, name)) != NULL; stunalloc(fullname)) { + for (;(fullname = padvance(&path, &opt, name)) != NULL; + stunalloc(fullname)) { idx++; - if (pathopt) { - if (strncmp(pathopt, "func", 4) == 0) { + if (opt) { + if (strncmp(opt, "func", 4) == 0) { /* handled below */ } else { continue; /* ignore unimplemented options */ } } if (fullname[0] != '/') cd = 1; if (stat(fullname, &statb) < 0) { if (errno != ENOENT && errno != ENOTDIR) e = errno; continue; } e = EACCES; /* if we fail, this will be the error */ if (!S_ISREG(statb.st_mode)) continue; - if (pathopt) { /* this is a %func directory */ + if (opt) { /* this is a %func directory */ readcmdfile(fullname); if ((cmdp = cmdlookup(name, 0)) == NULL || cmdp->cmdtype != CMDFUNCTION) error("%s not defined in %s", name, fullname); stunalloc(fullname); goto success; } #ifdef notdef if (statb.st_uid == geteuid()) { if ((statb.st_mode & 0100) == 0) goto loop; } else if (statb.st_gid == getegid()) { if ((statb.st_mode & 010) == 0) goto loop; } else { if ((statb.st_mode & 01) == 0) goto loop; } #endif TRACE(("searchexec \"%s\" returns \"%s\"\n", name, fullname)); INTOFF; stunalloc(fullname); cmdp = cmdlookup(name, 1); if (cmdp->cmdtype == CMDFUNCTION) cmdp = &loc_cmd; cmdp->cmdtype = CMDNORMAL; cmdp->param.index = idx; cmdp->special = 0; INTON; goto success; } if (act & DO_ERR) { if (e == ENOENT || e == ENOTDIR) outfmt(out2, "%s: not found\n", name); else outfmt(out2, "%s: %s\n", name, strerror(e)); } entry->cmdtype = CMDUNKNOWN; entry->u.index = 0; entry->special = 0; return; success: if (cd) cmdtable_cd = 1; entry->cmdtype = cmdp->cmdtype; entry->u = cmdp->param; entry->special = cmdp->special; } /* * Search the table of builtin commands. */ int find_builtin(const char *name, int *special) { const unsigned char *bp; size_t len; len = strlen(name); for (bp = builtincmd ; *bp ; bp += 2 + bp[0]) { if (bp[0] == len && memcmp(bp + 2, name, len) == 0) { *special = (bp[1] & BUILTIN_SPECIAL) != 0; return bp[1] & ~BUILTIN_SPECIAL; } } return -1; } /* * Called when a cd is done. If any entry in cmdtable depends on the current * directory, simply clear cmdtable completely. */ void hashcd(void) { if (cmdtable_cd) clearcmdentry(); } /* * Called before PATH is changed. The argument is the new value of PATH; * pathval() still returns the old value at this point. Called with * interrupts off. */ void changepath(const char *newval __unused) { clearcmdentry(); } /* * Clear out cached utility locations. */ void clearcmdentry(void) { struct tblentry **tblp; struct tblentry **pp; struct tblentry *cmdp; INTOFF; for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) { pp = tblp; while ((cmdp = *pp) != NULL) { if (cmdp->cmdtype == CMDNORMAL) { *pp = cmdp->next; ckfree(cmdp); } else { pp = &cmdp->next; } } } cmdtable_cd = 0; INTON; } /* * Locate a command in the command hash table. If "add" is nonzero, * add the command to the table if it is not already present. The * variable "lastcmdentry" is set to point to the address of the link * pointing to the entry, so that delete_cmd_entry can delete the * entry. */ static struct tblentry **lastcmdentry; static struct tblentry * cmdlookup(const char *name, int add) { unsigned int hashval; const char *p; struct tblentry *cmdp; struct tblentry **pp; size_t len; p = name; hashval = (unsigned char)*p << 4; while (*p) hashval += *p++; pp = &cmdtable[hashval % CMDTABLESIZE]; for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) { if (equal(cmdp->cmdname, name)) break; pp = &cmdp->next; } if (add && cmdp == NULL) { INTOFF; len = strlen(name); cmdp = *pp = ckmalloc(sizeof (struct tblentry) + len + 1); cmdp->next = NULL; cmdp->cmdtype = CMDUNKNOWN; memcpy(cmdp->cmdname, name, len + 1); INTON; } lastcmdentry = pp; return cmdp; } /* * Delete the command entry returned on the last lookup. */ static void delete_cmd_entry(void) { struct tblentry *cmdp; INTOFF; cmdp = *lastcmdentry; *lastcmdentry = cmdp->next; ckfree(cmdp); INTON; } /* * Add a new command entry, replacing any existing command entry for * the same name. */ static void addcmdentry(const char *name, struct cmdentry *entry) { struct tblentry *cmdp; INTOFF; cmdp = cmdlookup(name, 1); if (cmdp->cmdtype == CMDFUNCTION) { unreffunc(cmdp->param.func); } cmdp->cmdtype = entry->cmdtype; cmdp->param = entry->u; cmdp->special = entry->special; INTON; } /* * Define a shell function. */ void defun(const char *name, union node *func) { struct cmdentry entry; INTOFF; entry.cmdtype = CMDFUNCTION; entry.u.func = copyfunc(func); entry.special = 0; addcmdentry(name, &entry); INTON; } /* * Delete a function if it exists. * Called with interrupts off. */ int unsetfunc(const char *name) { struct tblentry *cmdp; if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->cmdtype == CMDFUNCTION) { unreffunc(cmdp->param.func); delete_cmd_entry(); return (0); } return (0); } /* * Check if a function by a certain name exists. */ int isfunc(const char *name) { struct tblentry *cmdp; cmdp = cmdlookup(name, 0); return (cmdp != NULL && cmdp->cmdtype == CMDFUNCTION); } /* * Shared code for the following builtin commands: * type, command -v, command -V */ int typecmd_impl(int argc, char **argv, int cmd, const char *path) { struct cmdentry entry; struct tblentry *cmdp; const char *const *pp; struct alias *ap; int i; int error1 = 0; if (path != pathval()) clearcmdentry(); for (i = 1; i < argc; i++) { /* First look at the keywords */ for (pp = parsekwd; *pp; pp++) if (**pp == *argv[i] && equal(*pp, argv[i])) break; if (*pp) { if (cmd == TYPECMD_SMALLV) out1fmt("%s\n", argv[i]); else out1fmt("%s is a shell keyword\n", argv[i]); continue; } /* Then look at the aliases */ if ((ap = lookupalias(argv[i], 1)) != NULL) { if (cmd == TYPECMD_SMALLV) { out1fmt("alias %s=", argv[i]); out1qstr(ap->val); outcslow('\n', out1); } else out1fmt("%s is an alias for %s\n", argv[i], ap->val); continue; } /* Then check if it is a tracked alias */ if ((cmdp = cmdlookup(argv[i], 0)) != NULL) { entry.cmdtype = cmdp->cmdtype; entry.u = cmdp->param; entry.special = cmdp->special; } else { /* Finally use brute force */ find_command(argv[i], &entry, 0, path); } switch (entry.cmdtype) { case CMDNORMAL: { if (strchr(argv[i], '/') == NULL) { const char *path2 = path; + const char *opt2; char *name; int j = entry.u.index; do { - name = padvance(&path2, argv[i]); + name = padvance(&path2, &opt2, argv[i]); stunalloc(name); } while (--j >= 0); if (cmd == TYPECMD_SMALLV) out1fmt("%s\n", name); else out1fmt("%s is%s %s\n", argv[i], (cmdp && cmd == TYPECMD_TYPE) ? " a tracked alias for" : "", name); } else { if (eaccess(argv[i], X_OK) == 0) { if (cmd == TYPECMD_SMALLV) out1fmt("%s\n", argv[i]); else out1fmt("%s is %s\n", argv[i], argv[i]); } else { if (cmd != TYPECMD_SMALLV) outfmt(out2, "%s: %s\n", argv[i], strerror(errno)); error1 |= 127; } } break; } case CMDFUNCTION: if (cmd == TYPECMD_SMALLV) out1fmt("%s\n", argv[i]); else out1fmt("%s is a shell function\n", argv[i]); break; case CMDBUILTIN: if (cmd == TYPECMD_SMALLV) out1fmt("%s\n", argv[i]); else if (entry.special) out1fmt("%s is a special shell builtin\n", argv[i]); else out1fmt("%s is a shell builtin\n", argv[i]); break; default: if (cmd != TYPECMD_SMALLV) outfmt(out2, "%s: not found\n", argv[i]); error1 |= 127; break; } } if (path != pathval()) clearcmdentry(); return error1; } /* * Locate and print what a word is... */ int typecmd(int argc, char **argv) { if (argc > 2 && strcmp(argv[1], "--") == 0) argc--, argv++; return typecmd_impl(argc, argv, TYPECMD_TYPE, bltinlookup("PATH", 1)); } Index: head/bin/sh/exec.h =================================================================== --- head/bin/sh/exec.h (revision 336319) +++ head/bin/sh/exec.h (revision 336320) @@ -1,77 +1,76 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)exec.h 8.3 (Berkeley) 6/8/95 * $FreeBSD$ */ /* values of cmdtype */ #define CMDUNKNOWN -1 /* no entry in table for command */ #define CMDNORMAL 0 /* command is an executable program */ #define CMDBUILTIN 1 /* command is a shell builtin */ #define CMDFUNCTION 2 /* command is a shell function */ /* values for typecmd_impl's third parameter */ enum { TYPECMD_SMALLV, /* command -v */ TYPECMD_BIGV, /* command -V */ TYPECMD_TYPE /* type */ }; union node; struct cmdentry { int cmdtype; union param { int index; struct funcdef *func; } u; int special; }; /* action to find_command() */ #define DO_ERR 0x01 /* prints errors */ #define DO_NOFUNC 0x02 /* don't return shell functions, for command */ -extern const char *pathopt; /* set by padvance */ extern int exerrno; /* last exec error */ void shellexec(char **, char **, const char *, int) __dead2; -char *padvance(const char **, const char *); +char *padvance(const char **, const char **, const char *); void find_command(const char *, struct cmdentry *, int, const char *); int find_builtin(const char *, int *); void hashcd(void); void changepath(const char *); void defun(const char *, union node *); int unsetfunc(const char *); int isfunc(const char *); int typecmd_impl(int, char **, int, const char *); void clearcmdentry(void); Index: head/bin/sh/main.c =================================================================== --- head/bin/sh/main.c (revision 336319) +++ head/bin/sh/main.c (revision 336320) @@ -1,351 +1,352 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char const copyright[] = "@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/28/95"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include "shell.h" #include "main.h" #include "mail.h" #include "options.h" #include "output.h" #include "parser.h" #include "nodes.h" #include "expand.h" #include "eval.h" #include "jobs.h" #include "input.h" #include "trap.h" #include "var.h" #include "show.h" #include "memalloc.h" #include "error.h" #include "mystring.h" #include "exec.h" #include "cd.h" #include "redir.h" #include "builtins.h" int rootpid; int rootshell; struct jmploc main_handler; int localeisutf8, initial_localeisutf8; static void reset(void); static void cmdloop(int); static void read_profile(const char *); static char *find_dot_file(char *); /* * Main routine. We initialize things, parse the arguments, execute * profiles if we're a login shell, and then call cmdloop to execute * commands. The setjmp call sets up the location to jump to when an * exception occurs. When an exception occurs the variable "state" * is used to figure out how far we had gotten. */ int main(int argc, char *argv[]) { struct stackmark smark, smark2; volatile int state; char *shinit; (void) setlocale(LC_ALL, ""); initcharset(); state = 0; if (setjmp(main_handler.loc)) { switch (exception) { case EXEXEC: exitstatus = exerrno; break; case EXERROR: exitstatus = 2; break; default: break; } if (state == 0 || iflag == 0 || ! rootshell || exception == EXEXIT) exitshell(exitstatus); reset(); if (exception == EXINT) out2fmt_flush("\n"); popstackmark(&smark); FORCEINTON; /* enable interrupts */ if (state == 1) goto state1; else if (state == 2) goto state2; else if (state == 3) goto state3; else goto state4; } handler = &main_handler; #ifdef DEBUG opentrace(); trputs("Shell args: "); trargs(argv); #endif rootpid = getpid(); rootshell = 1; INTOFF; initvar(); setstackmark(&smark); setstackmark(&smark2); procargs(argc, argv); pwd_init(iflag); INTON; if (iflag) chkmail(1); if (argv[0] && argv[0][0] == '-') { state = 1; read_profile("/etc/profile"); state1: state = 2; if (privileged == 0) read_profile("${HOME-}/.profile"); else read_profile("/etc/suid_profile"); } state2: state = 3; if (!privileged && iflag) { if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') { state = 3; read_profile(shinit); } } state3: state = 4; popstackmark(&smark2); if (minusc) { evalstring(minusc, sflag ? 0 : EV_EXIT); } state4: if (sflag || minusc == NULL) { cmdloop(1); } exitshell(exitstatus); /*NOTREACHED*/ return 0; } static void reset(void) { reseteval(); resetinput(); } /* * Read and execute commands. "Top" is nonzero for the top level command * loop; it turns on prompting if the shell is interactive. */ static void cmdloop(int top) { union node *n; struct stackmark smark; int inter; int numeof = 0; TRACE(("cmdloop(%d) called\n", top)); setstackmark(&smark); for (;;) { if (pendingsig) dotrap(); inter = 0; if (iflag && top) { inter++; showjobs(1, SHOWJOBS_DEFAULT); chkmail(0); flushout(&output); } n = parsecmd(inter); /* showtree(n); DEBUG */ if (n == NEOF) { if (!top || numeof >= 50) break; if (!stoppedjobs()) { if (!Iflag) break; out2fmt_flush("\nUse \"exit\" to leave shell.\n"); } numeof++; } else if (n != NULL && nflag == 0) { job_warning = (job_warning == 2) ? 1 : 0; numeof = 0; evaltree(n, 0); } popstackmark(&smark); setstackmark(&smark); if (evalskip != 0) { if (evalskip == SKIPRETURN) evalskip = 0; break; } } popstackmark(&smark); } /* * Read /etc/profile or .profile. Return on error. */ static void read_profile(const char *name) { int fd; const char *expandedname; expandedname = expandstr(name); if (expandedname == NULL) return; INTOFF; if ((fd = open(expandedname, O_RDONLY | O_CLOEXEC)) >= 0) setinputfd(fd, 1); INTON; if (fd < 0) return; cmdloop(0); popfile(); } /* * Read a file containing shell functions. */ void readcmdfile(const char *name) { setinputfile(name, 1); cmdloop(0); popfile(); } /* * Take commands from a file. To be compatible we should do a path * search for the file, which is necessary to find sub-commands. */ static char * find_dot_file(char *basename) { char *fullname; + const char *opt; const char *path = pathval(); struct stat statb; /* don't try this for absolute or relative paths */ if( strchr(basename, '/')) return basename; - while ((fullname = padvance(&path, basename)) != NULL) { + while ((fullname = padvance(&path, &opt, basename)) != NULL) { if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) { /* * Don't bother freeing here, since it will * be freed by the caller. */ return fullname; } stunalloc(fullname); } return basename; } int dotcmd(int argc, char **argv) { char *filename, *fullname; if (argc < 2) error("missing filename"); exitstatus = 0; /* * Because we have historically not supported any options, * only treat "--" specially. */ filename = argc > 2 && strcmp(argv[1], "--") == 0 ? argv[2] : argv[1]; fullname = find_dot_file(filename); setinputfile(fullname, 1); commandname = fullname; cmdloop(0); popfile(); return exitstatus; } int exitcmd(int argc, char **argv) { if (stoppedjobs()) return 0; if (argc > 1) exitshell(number(argv[1])); else exitshell_savedstatus(); } Index: head/bin/sh/tests/builtins/Makefile =================================================================== --- head/bin/sh/tests/builtins/Makefile (revision 336319) +++ head/bin/sh/tests/builtins/Makefile (revision 336320) @@ -1,186 +1,187 @@ # $FreeBSD$ PACKAGE= tests .include TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T} .PATH: ${.CURDIR:H} ATF_TESTS_SH= functional_test ${PACKAGE}FILES+= alias.0 alias.0.stdout ${PACKAGE}FILES+= alias.1 alias.1.stderr ${PACKAGE}FILES+= alias3.0 alias3.0.stdout ${PACKAGE}FILES+= alias4.0 ${PACKAGE}FILES+= break1.0 ${PACKAGE}FILES+= break2.0 break2.0.stdout ${PACKAGE}FILES+= break3.0 ${PACKAGE}FILES+= break4.4 ${PACKAGE}FILES+= break5.4 ${PACKAGE}FILES+= break6.0 ${PACKAGE}FILES+= builtin1.0 ${PACKAGE}FILES+= case1.0 ${PACKAGE}FILES+= case2.0 ${PACKAGE}FILES+= case3.0 ${PACKAGE}FILES+= case4.0 ${PACKAGE}FILES+= case5.0 ${PACKAGE}FILES+= case6.0 ${PACKAGE}FILES+= case7.0 ${PACKAGE}FILES+= case8.0 ${PACKAGE}FILES+= case9.0 ${PACKAGE}FILES+= case10.0 ${PACKAGE}FILES+= case11.0 ${PACKAGE}FILES+= case12.0 ${PACKAGE}FILES+= case13.0 ${PACKAGE}FILES+= case14.0 ${PACKAGE}FILES+= case15.0 ${PACKAGE}FILES+= case16.0 ${PACKAGE}FILES+= case17.0 ${PACKAGE}FILES+= case18.0 ${PACKAGE}FILES+= case19.0 ${PACKAGE}FILES+= case20.0 ${PACKAGE}FILES+= case21.0 ${PACKAGE}FILES+= case22.0 ${PACKAGE}FILES+= case23.0 ${PACKAGE}FILES+= cd1.0 ${PACKAGE}FILES+= cd2.0 ${PACKAGE}FILES+= cd3.0 ${PACKAGE}FILES+= cd4.0 ${PACKAGE}FILES+= cd5.0 ${PACKAGE}FILES+= cd6.0 ${PACKAGE}FILES+= cd7.0 ${PACKAGE}FILES+= cd8.0 ${PACKAGE}FILES+= cd9.0 cd9.0.stdout ${PACKAGE}FILES+= cd10.0 +${PACKAGE}FILES+= cd11.0 ${PACKAGE}FILES+= command1.0 ${PACKAGE}FILES+= command2.0 ${PACKAGE}FILES+= command3.0 ${PACKAGE}FILES+= command3.0.stdout ${PACKAGE}FILES+= command4.0 ${PACKAGE}FILES+= command5.0 ${PACKAGE}FILES+= command5.0.stdout ${PACKAGE}FILES+= command6.0 ${PACKAGE}FILES+= command6.0.stdout ${PACKAGE}FILES+= command7.0 ${PACKAGE}FILES+= command8.0 ${PACKAGE}FILES+= command9.0 ${PACKAGE}FILES+= command10.0 ${PACKAGE}FILES+= command11.0 ${PACKAGE}FILES+= command12.0 ${PACKAGE}FILES+= dot1.0 ${PACKAGE}FILES+= dot2.0 ${PACKAGE}FILES+= dot3.0 ${PACKAGE}FILES+= dot4.0 ${PACKAGE}FILES+= echo1.0 ${PACKAGE}FILES+= echo2.0 ${PACKAGE}FILES+= echo3.0 ${PACKAGE}FILES+= eval1.0 ${PACKAGE}FILES+= eval2.0 ${PACKAGE}FILES+= eval3.0 ${PACKAGE}FILES+= eval4.0 ${PACKAGE}FILES+= eval5.0 ${PACKAGE}FILES+= eval6.0 ${PACKAGE}FILES+= eval7.0 ${PACKAGE}FILES+= eval8.7 ${PACKAGE}FILES+= exec1.0 ${PACKAGE}FILES+= exec2.0 ${PACKAGE}FILES+= exit1.0 ${PACKAGE}FILES+= exit2.8 ${PACKAGE}FILES+= exit3.0 ${PACKAGE}FILES+= export1.0 ${PACKAGE}FILES+= fc1.0 ${PACKAGE}FILES+= fc2.0 ${PACKAGE}FILES+= for1.0 ${PACKAGE}FILES+= for2.0 ${PACKAGE}FILES+= for3.0 ${PACKAGE}FILES+= getopts1.0 getopts1.0.stdout ${PACKAGE}FILES+= getopts2.0 getopts2.0.stdout ${PACKAGE}FILES+= getopts3.0 ${PACKAGE}FILES+= getopts4.0 ${PACKAGE}FILES+= getopts5.0 ${PACKAGE}FILES+= getopts6.0 ${PACKAGE}FILES+= getopts7.0 ${PACKAGE}FILES+= getopts8.0 getopts8.0.stdout ${PACKAGE}FILES+= getopts9.0 getopts9.0.stdout ${PACKAGE}FILES+= getopts10.0 ${PACKAGE}FILES+= hash1.0 hash1.0.stdout ${PACKAGE}FILES+= hash2.0 hash2.0.stdout ${PACKAGE}FILES+= hash3.0 hash3.0.stdout ${PACKAGE}FILES+= hash4.0 ${PACKAGE}FILES+= jobid1.0 ${PACKAGE}FILES+= jobid2.0 ${PACKAGE}FILES+= kill1.0 kill2.0 ${PACKAGE}FILES+= lineno.0 lineno.0.stdout ${PACKAGE}FILES+= lineno2.0 ${PACKAGE}FILES+= lineno3.0 lineno3.0.stdout ${PACKAGE}FILES+= local1.0 ${PACKAGE}FILES+= local2.0 ${PACKAGE}FILES+= local3.0 ${PACKAGE}FILES+= local4.0 ${PACKAGE}FILES+= local5.0 ${PACKAGE}FILES+= local6.0 ${PACKAGE}FILES+= local7.0 .if ${MK_NLS} != "no" ${PACKAGE}FILES+= locale1.0 .endif ${PACKAGE}FILES+= locale2.0 ${PACKAGE}FILES+= printf1.0 ${PACKAGE}FILES+= printf2.0 ${PACKAGE}FILES+= printf3.0 ${PACKAGE}FILES+= printf4.0 ${PACKAGE}FILES+= read1.0 read1.0.stdout ${PACKAGE}FILES+= read2.0 ${PACKAGE}FILES+= read3.0 read3.0.stdout ${PACKAGE}FILES+= read4.0 read4.0.stdout ${PACKAGE}FILES+= read5.0 ${PACKAGE}FILES+= read6.0 ${PACKAGE}FILES+= read7.0 ${PACKAGE}FILES+= read8.0 ${PACKAGE}FILES+= read9.0 ${PACKAGE}FILES+= return1.0 ${PACKAGE}FILES+= return2.1 ${PACKAGE}FILES+= return3.1 ${PACKAGE}FILES+= return4.0 ${PACKAGE}FILES+= return5.0 ${PACKAGE}FILES+= return6.4 ${PACKAGE}FILES+= return7.4 ${PACKAGE}FILES+= return8.0 ${PACKAGE}FILES+= set1.0 ${PACKAGE}FILES+= set2.0 ${PACKAGE}FILES+= set3.0 ${PACKAGE}FILES+= trap1.0 ${PACKAGE}FILES+= trap10.0 ${PACKAGE}FILES+= trap11.0 ${PACKAGE}FILES+= trap12.0 ${PACKAGE}FILES+= trap13.0 ${PACKAGE}FILES+= trap14.0 ${PACKAGE}FILES+= trap15.0 ${PACKAGE}FILES+= trap16.0 ${PACKAGE}FILES+= trap17.0 ${PACKAGE}FILES+= trap2.0 ${PACKAGE}FILES+= trap3.0 ${PACKAGE}FILES+= trap4.0 ${PACKAGE}FILES+= trap5.0 ${PACKAGE}FILES+= trap6.0 ${PACKAGE}FILES+= trap7.0 ${PACKAGE}FILES+= trap8.0 ${PACKAGE}FILES+= trap9.0 ${PACKAGE}FILES+= type1.0 type1.0.stderr ${PACKAGE}FILES+= type2.0 ${PACKAGE}FILES+= type3.0 ${PACKAGE}FILES+= unalias.0 ${PACKAGE}FILES+= var-assign.0 ${PACKAGE}FILES+= var-assign2.0 ${PACKAGE}FILES+= wait1.0 ${PACKAGE}FILES+= wait2.0 ${PACKAGE}FILES+= wait3.0 ${PACKAGE}FILES+= wait4.0 ${PACKAGE}FILES+= wait5.0 ${PACKAGE}FILES+= wait6.0 ${PACKAGE}FILES+= wait7.0 ${PACKAGE}FILES+= wait8.0 ${PACKAGE}FILES+= wait9.127 ${PACKAGE}FILES+= wait10.0 .include Index: head/bin/sh/tests/builtins/cd11.0 =================================================================== --- head/bin/sh/tests/builtins/cd11.0 (nonexistent) +++ head/bin/sh/tests/builtins/cd11.0 (revision 336320) @@ -0,0 +1,24 @@ +# $FreeBSD$ + +set -e +T=$(mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXX") +trap 'rm -rf "$T"' 0 + +mkdir "$T/%?^&*" +cd -P "$T/%?^&*" +D=$(pwd) + +mkdir a a/1 b b/1 b/2 + +CDPATH=$D/a: +# Basic test. +cd 1 >/dev/null +[ "$(pwd)" = "$D/a/1" ] +# Test that the current directory is not checked before CDPATH. +cd "$D/b" +cd 1 >/dev/null +[ "$(pwd)" = "$D/a/1" ] +# Test not using a CDPATH entry. +cd "$D/b" +cd 2 +[ "$(pwd)" = "$D/b/2" ] Property changes on: head/bin/sh/tests/builtins/cd11.0 ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property