From owner-svn-src-all@FreeBSD.ORG Sat May 21 22:03:07 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 25741106564A; Sat, 21 May 2011 22:03:07 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0BD9C8FC13; Sat, 21 May 2011 22:03:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p4LM36Rn047165; Sat, 21 May 2011 22:03:06 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p4LM362v047158; Sat, 21 May 2011 22:03:06 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201105212203.p4LM362v047158@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 21 May 2011 22:03:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222165 - in head: bin/sh tools/regression/bin/sh/parser X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 May 2011 22:03:07 -0000 Author: jilles Date: Sat May 21 22:03:06 2011 New Revision: 222165 URL: http://svn.freebsd.org/changeset/base/222165 Log: sh: Expand aliases after assignments and redirections. Added: head/tools/regression/bin/sh/parser/alias4.0 (contents, props changed) head/tools/regression/bin/sh/parser/alias5.0 (contents, props changed) Modified: head/bin/sh/eval.c head/bin/sh/parser.c head/bin/sh/parser.h head/bin/sh/sh.1 Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Sat May 21 20:21:20 2011 (r222164) +++ head/bin/sh/eval.c Sat May 21 22:03:06 2011 (r222165) @@ -714,15 +714,9 @@ evalcommand(union node *cmd, int flags, oexitstatus = exitstatus; exitstatus = 0; for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) { - char *p = argp->narg.text; - if (varflag && is_name(*p)) { - do { - p++; - } while (is_in_name(*p)); - if (*p == '=') { - expandarg(argp, &varlist, EXP_VARTILDE); - continue; - } + if (varflag && isassignment(argp->narg.text)) { + expandarg(argp, &varlist, EXP_VARTILDE); + continue; } expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); varflag = 0; Modified: head/bin/sh/parser.c ============================================================================== --- head/bin/sh/parser.c Sat May 21 20:21:20 2011 (r222164) +++ head/bin/sh/parser.c Sat May 21 22:03:06 2011 (r222165) @@ -619,6 +619,7 @@ simplecmd(union node **rpp, union node * union node **orig_rpp = rpp; union node *n = NULL; int special; + int savecheckkwd; /* If we don't have any redirections already, then we must reset */ /* rpp to be the address of the local redir variable. */ @@ -634,7 +635,10 @@ simplecmd(union node **rpp, union node * */ orig_rpp = rpp; + savecheckkwd = CHKALIAS; + for (;;) { + checkkwd = savecheckkwd; if (readtoken() == TWORD) { n = (union node *)stalloc(sizeof (struct narg)); n->type = NARG; @@ -642,6 +646,8 @@ simplecmd(union node **rpp, union node * n->narg.backquote = backquotelist; *app = n; app = &n->narg.next; + if (savecheckkwd != 0 && !isassignment(wordtext)) + savecheckkwd = 0; } else if (lasttoken == TREDIR) { *rpp = n = redirnode; rpp = &n->nfile.next; @@ -1859,6 +1865,22 @@ goodname(const char *name) } +int +isassignment(const char *p) +{ + if (!is_name(*p)) + return 0; + p++; + for (;;) { + if (*p == '=') + return 1; + else if (!is_in_name(*p)) + return 0; + p++; + } +} + + /* * Called when an unexpected token is read during the parse. The argument * is the token that is expected, or -1 if more than one type of token can Modified: head/bin/sh/parser.h ============================================================================== --- head/bin/sh/parser.h Sat May 21 20:21:20 2011 (r222164) +++ head/bin/sh/parser.h Sat May 21 22:03:06 2011 (r222165) @@ -80,4 +80,5 @@ extern const char *const parsekwd[]; union node *parsecmd(int); void fixredir(union node *, const char *, int); int goodname(const char *); +int isassignment(const char *); char *getprompt(void *); Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Sat May 21 20:21:20 2011 (r222164) +++ head/bin/sh/sh.1 Sat May 21 22:03:06 2011 (r222165) @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd May 20, 2011 +.Dd May 21, 2011 .Dt SH 1 .Os .Sh NAME @@ -506,8 +506,8 @@ The following are keywords: An alias is a name and corresponding value set using the .Ic alias built-in command. -Whenever a keyword may occur (see above), -and after checking for keywords, the shell +Wherever the command word of a simple command may occur, +and after checking for keywords if a keyword may occur, the shell checks the word to see if it matches an alias. If it does, it replaces it in the input stream with its value. For example, if there is an alias called Added: head/tools/regression/bin/sh/parser/alias4.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/parser/alias4.0 Sat May 21 22:03:06 2011 (r222165) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +alias alias0=exit +eval 'x=1 alias0 0' +exit 1 Added: head/tools/regression/bin/sh/parser/alias5.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/parser/alias5.0 Sat May 21 22:03:06 2011 (r222165) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +alias alias0=exit +eval '