Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Dynamically detect the way the shell matches \ in a p...
details: https://anonhg.NetBSD.org/src/rev/3acfc84c6067
branches: trunk
changeset: 994057:3acfc84c6067
user: kre <kre%NetBSD.org@localhost>
date: Thu Oct 18 04:24:43 2018 +0000
description:
Dynamically detect the way the shell matches \ in a pattern,
and use whatever works for the sh running this script. Previously
we were using the (broken, and incorrect) method that worked in
old broken NetBSD sh's (and some others) and not the method that
works with the current (fixed) /bin/sh and other correct shells
(like bash). (For an exotic reason, in the particular use case,
both methods work with ksh93, but it is also generally correct).
This hasn't really mattered, as the difference is only significant
(only causes actual issues - the build fails) when compiling with DEBUG
enabled, which is something that most sane humans would never do, if they
want to retain that sanity.
The problem was detected by Patrick Welche when looking for an
unrelated problem, which was once considered to be a possible sh
problem, but turned out to be something entirely different.
XXX pullup -8
diffstat:
bin/sh/mkinit.sh | 34 ++++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 2 deletions(-)
diffs (49 lines):
diff -r 28a99387e300 -r 3acfc84c6067 bin/sh/mkinit.sh
--- a/bin/sh/mkinit.sh Thu Oct 18 04:22:22 2018 +0000
+++ b/bin/sh/mkinit.sh Thu Oct 18 04:24:43 2018 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: mkinit.sh,v 1.8 2018/09/16 22:31:30 kre Exp $
+# $NetBSD: mkinit.sh,v 1.9 2018/10/18 04:24:43 kre Exp $
# Copyright (c) 2003 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -33,7 +33,37 @@
nl='
'
openparen='('
-backslash='\'
+
+# shells have bugs (including older NetBSD sh) in how \ is
+# used in pattern matching. So work out what the shell
+# running this script expects. We could also just use a
+# literal \ in the pattern, which would need to be quoted
+# of course, but then we'd run into a whole host of potential
+# other shell bugs (both with the quoting in the pattern, and
+# with the matching that follows if that works as inended).
+# Far easier, and more reliable, is to just work out what works,
+# and then use it, which more or less mandates using a variable...
+backslash='\\'
+var='abc\' # dummy test case.
+if [ "$var" = "${var%$backslash}" ]
+then
+ # buggy sh, try the broken way
+ backslash='\'
+ if [ "$var" = "${var%$backslash}" ]
+ then
+ printf >&2 "$0: %s\n" 'No pattern match with \ (broken shell)'
+ exit 1
+ fi
+fi
+# We know we can detect the presence of a trailing \, which is all we need.
+# Now to confirm we will not generate false matches.
+var='abc'
+if [ "$var" != "${var%$backslash}" ]
+then
+ printf >&2 "$0: %s\n" 'Bogus pattern match with \ (broken shell)'
+ exit 1
+fi
+unset var
includes=' "shell.h" "mystring.h" "init.h" '
defines=
Home |
Main Index |
Thread Index |
Old Index