diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2014-07-12 10:27:30 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2014-07-12 10:27:30 +0000 |
commit | 5ddabb8348165b7bdd1385288a17937bbda76743 (patch) | |
tree | 9565d5942cb94174c2fcbea095eedbaca8a3c50f /bin | |
parent | 0c7b5530d66c949be9f3f01a5755cbcaf384ea23 (diff) | |
download | src-5ddabb8348165b7bdd1385288a17937bbda76743.tar.gz src-5ddabb8348165b7bdd1385288a17937bbda76743.zip |
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.
Notes
Notes:
svn path=/head/; revision=268568
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/expand.c | 13 | ||||
-rw-r--r-- | bin/sh/tests/parameters/Makefile | 1 | ||||
-rw-r--r-- | bin/sh/tests/parameters/positional4.0 | 4 |
3 files changed, 11 insertions, 7 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c index a126ca60a6dd..b8ef5ea1b67d 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -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; } diff --git a/bin/sh/tests/parameters/Makefile b/bin/sh/tests/parameters/Makefile index 4f9ae31ce3b5..25742263e827 100644 --- a/bin/sh/tests/parameters/Makefile +++ b/bin/sh/tests/parameters/Makefile @@ -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 diff --git a/bin/sh/tests/parameters/positional4.0 b/bin/sh/tests/parameters/positional4.0 new file mode 100644 index 000000000000..c1c380c0feac --- /dev/null +++ b/bin/sh/tests/parameters/positional4.0 @@ -0,0 +1,4 @@ +# $FreeBSD$ + +set -- "x$0" 2 3 4 5 6 7 8 9 "y$0" +[ "${01}.${010}" = "$1.${10}" ] |