From owner-svn-src-all@FreeBSD.ORG Sat Apr 3 22:04:45 2010 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 484ED106566B; Sat, 3 Apr 2010 22:04:45 +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 36B2E8FC12; Sat, 3 Apr 2010 22:04:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o33M4jAl013345; Sat, 3 Apr 2010 22:04:45 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o33M4jh4013342; Sat, 3 Apr 2010 22:04:45 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201004032204.o33M4jh4013342@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 3 Apr 2010 22:04:45 +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: r206150 - in head: bin/sh tools/regression/bin/sh/expansion 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, 03 Apr 2010 22:04:45 -0000 Author: jilles Date: Sat Apr 3 22:04:44 2010 New Revision: 206150 URL: http://svn.freebsd.org/changeset/base/206150 Log: sh: Do tilde expansion in substitutions. This applies to word in ${v-word}, ${v+word}, ${v=word}, ${v?word} (which inherits quoting from the outside) and in ${v%word}, ${v%%word}, ${v#word}, ${v##word} (which does not inherit any quoting). In all cases tilde expansion is only attempted at the start of word, even if word contains spaces. This agrees with POSIX and other shells. This is the last part of the patch tested in the exp-run. Exp-run done by: erwin (with some other sh(1) changes) Added: head/tools/regression/bin/sh/expansion/tilde2.0 (contents, props changed) Modified: head/bin/sh/expand.c Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Sat Apr 3 21:56:24 2010 (r206149) +++ head/bin/sh/expand.c Sat Apr 3 22:04:44 2010 (r206150) @@ -273,7 +273,6 @@ exptilde(char *p, int flag) switch(c) { case CTLESC: /* This means CTL* are always considered quoted. */ case CTLVAR: - case CTLENDVAR: case CTLBACKQ: case CTLBACKQ | CTLQUOTE: case CTLARI: @@ -285,6 +284,7 @@ exptilde(char *p, int flag) goto done; break; case '/': + case CTLENDVAR: goto done; } p++; @@ -506,9 +506,9 @@ subevalvar(char *p, char *str, int strlo int amount; herefd = -1; - argstr(p, subtype == VSTRIMLEFT || subtype == VSTRIMLEFTMAX || + argstr(p, (subtype == VSTRIMLEFT || subtype == VSTRIMLEFTMAX || subtype == VSTRIMRIGHT || subtype == VSTRIMRIGHTMAX ? - EXP_CASE : 0); + EXP_CASE : 0) | EXP_TILDE); STACKSTRNUL(expdest); herefd = saveherefd; argbackq = saveargbackq; Added: head/tools/regression/bin/sh/expansion/tilde2.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/expansion/tilde2.0 Sat Apr 3 22:04:44 2010 (r206150) @@ -0,0 +1,90 @@ +# $FreeBSD$ + +HOME=/tmp +roothome=~root +if [ "$roothome" = "~root" ]; then + echo "~root is not expanded!" + exit 2 +fi + +testcase() { + code="$1" + expected="$2" + oIFS="$IFS" + eval "$code" + IFS='|' + result="$#|$*" + IFS="$oIFS" + if [ "x$result" = "x$expected" ]; then + ok=x$ok + else + failures=x$failures + echo "For $code, expected $expected actual $result" + fi +} + +testcase 'set -- ${$+~}' '1|/tmp' +testcase 'set -- ${$+~/}' '1|/tmp/' +testcase 'set -- ${$+~/foo}' '1|/tmp/foo' +testcase 'set -- ${$+x~}' '1|x~' +testcase 'set -- ${$+~root}' "1|$roothome" +testcase 'set -- ${$+"~"}' '1|~' +testcase 'set -- ${$+"~/"}' '1|~/' +testcase 'set -- ${$+"~/foo"}' '1|~/foo' +testcase 'set -- ${$+"x~"}' '1|x~' +testcase 'set -- ${$+"~root"}' "1|~root" +testcase 'set -- "${$+~}"' '1|~' +testcase 'set -- "${$+~/}"' '1|~/' +testcase 'set -- "${$+~/foo}"' '1|~/foo' +testcase 'set -- "${$+x~}"' '1|x~' +testcase 'set -- "${$+~root}"' "1|~root" +testcase 'set -- ${HOME#~}' '0|' +h=~ +testcase 'set -- "$h"' '1|/tmp' +f=~/foo +testcase 'set -- "$f"' '1|/tmp/foo' +testcase 'set -- ${f#~}' '1|/foo' +testcase 'set -- ${f#~/}' '1|foo' + +ooIFS=$IFS +IFS=m +testcase 'set -- ${$+~}' '1|/tmp' +testcase 'set -- ${$+~/foo}' '1|/tmp/foo' +testcase 'set -- ${$+$h}' '2|/t|p' +testcase 'set -- ${HOME#~}' '0|' +IFS=$ooIFS + +t=\~ +testcase 'set -- ${$+$t}' '1|~' +r=$(cat <