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 @@ varvalue(const char *name, int quoted, int subtype, int flag) 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}" ]