Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/miniroot The idiom



details:   https://anonhg.NetBSD.org/src/rev/720dc6bf2139
branches:  trunk
changeset: 467270:720dc6bf2139
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Jan 19 00:50:25 2020 +0000

description:
The idiom

        set $whatever
        while [ $# - gt 10 ]; do shift 10; done
        eval echo \$$#

fails when $# turns out to be 10 (or any multiple), it would need
to be instead

        while [ $# -ge 10 ]; do shift 9; done

but there hasn't been a shell that cannot handle ${10} (etc) correctly
in a very long time, so let's just use that instead (properly quoted,
in case IFS happens to contain a digit for some bizarre reason).

We should also "set -f" / "set +f" (or better, restore the prev setting of -f)
around the "set $whatever" part, but if that was ever going to cause a problem
here, it would have already, so leave that for now.

diffstat:

 distrib/miniroot/install.sub |  8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diffs (30 lines):

diff -r bf5c5b5b566f -r 720dc6bf2139 distrib/miniroot/install.sub
--- a/distrib/miniroot/install.sub      Sat Jan 18 22:17:34 2020 +0000
+++ b/distrib/miniroot/install.sub      Sun Jan 19 00:50:25 2020 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-#      $NetBSD: install.sub,v 1.51 2020/01/12 03:56:14 tsutsui Exp $
+#      $NetBSD: install.sub,v 1.52 2020/01/19 00:50:25 kre Exp $
 #
 # Copyright (c) 1996 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -114,8 +114,7 @@
        read _a; set -- $_a
        IFS="$_oifs"
        if [ "$1" = "" ]; then return; fi
-       while [ "$#" -gt 10 ]; do shift 10; done
-       eval echo \$$#
+       eval echo '"${'"$#"'}"'
 }
 
 firstchar () {
@@ -135,8 +134,7 @@
        IFS="/"
        set -- $1
        IFS="$_oifs"
-       while [ "$#" -gt 10 ]; do shift 10; done
-       eval echo \$$#
+       eval echo '"${'"$#"'}"'
 }
 
 dir_has_sets() {



Home | Main Index | Thread Index | Old Index