Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Jul 2014 10:27:31 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r268568 - in head/bin/sh: . tests/parameters
Message-ID:  <201407121027.s6CARVeY013979@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sat Jul 12 10:27:30 2014
New Revision: 268568
URL: http://svnweb.freebsd.org/changeset/base/268568

Log:
  sh: Consistently treat ${01} like $1.
  
  Leading zeroes were ignored when checking whether a positional parameter is
  set, but not when expanding its value. Ignore leading zeroes in any case.

Added:
  head/bin/sh/tests/parameters/positional4.0   (contents, props changed)
Modified:
  head/bin/sh/expand.c
  head/bin/sh/tests/parameters/Makefile

Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c	Sat Jul 12 10:18:33 2014	(r268567)
+++ head/bin/sh/expand.c	Sat Jul 12 10:27:30 2014	(r268568)
@@ -928,17 +928,16 @@ numvar:
 				STPUTC(sep, expdest);
 		}
 		break;
-	case '0':
-		p = arg0;
-		strtodest(p, flag, subtype, quoted);
-		break;
 	default:
 		if (is_digit(*name)) {
 			num = atoi(name);
-			if (num > 0 && num <= shellparam.nparam) {
+			if (num == 0)
+				p = arg0;
+			else if (num > 0 && num <= shellparam.nparam)
 				p = shellparam.p[num - 1];
-				strtodest(p, flag, subtype, quoted);
-			}
+			else
+				break;
+			strtodest(p, flag, subtype, quoted);
 		}
 		break;
 	}

Modified: head/bin/sh/tests/parameters/Makefile
==============================================================================
--- head/bin/sh/tests/parameters/Makefile	Sat Jul 12 10:18:33 2014	(r268567)
+++ head/bin/sh/tests/parameters/Makefile	Sat Jul 12 10:27:30 2014	(r268568)
@@ -14,6 +14,7 @@ FILES+=		optind2.0
 FILES+=		positional1.0
 FILES+=		positional2.0
 FILES+=		positional3.0
+FILES+=		positional4.0
 FILES+=		pwd1.0
 FILES+=		pwd2.0
 

Added: head/bin/sh/tests/parameters/positional4.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/bin/sh/tests/parameters/positional4.0	Sat Jul 12 10:27:30 2014	(r268568)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -- "x$0" 2 3 4 5 6 7 8 9 "y$0"
+[ "${01}.${010}" = "$1.${10}" ]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407121027.s6CARVeY013979>