From owner-svn-src-head@FreeBSD.ORG Mon May 11 19:50:03 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6F0EEDD8; Mon, 11 May 2015 19:50:03 +0000 (UTC) Received: from shxd.cx (mail.shxd.cx [64.201.244.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 58CE212C4; Mon, 11 May 2015 19:50:03 +0000 (UTC) Received: from [64.201.244.132] (port=55736 helo=[10.0.0.102]) by shxd.cx with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.77 (FreeBSD)) (envelope-from ) id 1Yrsxl-000864-4h; Mon, 11 May 2015 12:02:01 -0700 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) Subject: Re: svn commit: r282672 - head/etc/rc.d From: Devin Teske In-Reply-To: <555106B5.3010104@FreeBSD.org> Date: Mon, 11 May 2015 12:49:58 -0700 Cc: Brooks Davis , John Baldwin , Xin LI , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" , Devin Teske Content-Transfer-Encoding: quoted-printable Message-Id: <5AE2B9A2-FF6E-422A-B2E2-7E6CA85999BD@FreeBSD.org> References: <201505082336.t48NaWRS080408@svn.freebsd.org> <20150511191850.GC68045@spindle.one-eyed-alien.net> <9FB76653-EF89-48E5-B4E8-A2006923B76A@FreeBSD.org> <555106B5.3010104@FreeBSD.org> To: Eric van Gyzen X-Mailer: Apple Mail (2.1990.1) Sender: devin@shxd.cx X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 May 2015 19:50:03 -0000 > On May 11, 2015, at 12:44 PM, Eric van Gyzen = wrote: >=20 > On 05/11/2015 15:37, Devin Teske wrote: >>=20 >>> On May 11, 2015, at 12:18 PM, Brooks Davis > wrote: >>>=20 >>> On Sun, May 10, 2015 at 03:45:48PM -0400, John Baldwin wrote: >>>>=20 >>>>> On May 8, 2015, at 19:36, Xin LI > wrote: >>>>>=20 >>>>> Author: delphij >>>>> Date: Fri May 8 23:36:31 2015 >>>>> New Revision: 282672 >>>>> URL: https://svnweb.freebsd.org/changeset/base/282672 >>>>>=20 >>>>> Log: >>>>> Always convert uuid to lower case. >>>>>=20 >>>>> MFC after: 2 weeks >>>>>=20 >>>>> Modified: >>>>> head/etc/rc.d/hostid >>>>>=20 >>>>> Modified: head/etc/rc.d/hostid >>>>> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D >>>>> --- head/etc/rc.d/hostid Fri May 8 23:29:42 2015 (r282671) >>>>> +++ head/etc/rc.d/hostid Fri May 8 23:36:31 2015 (r282672) >>>>> @@ -58,7 +58,7 @@ hostid_set() >>>>>=20 >>>>> valid_hostid() >>>>> { >>>>> - uuid=3D$1 >>>>> + uuid=3D$(echo $1 | tr '[:upper:]' '[:lower:]') >>>>=20 >>>> tr is in /usr/bin so this breaks systems with a separate /usr. = Perhaps you could use dd with conv=3Dlcase instead? >>>=20 >>> Alterntively, a shell function "ltr" exists in rc.subr for this = purpose. >>>=20 >>=20 >> ltr would not work in this situation, for multiple reasons. >>=20 >> 1. ltr doesn=E2=80=99t support character classes >> 2. ltr is for replacing one or more characters (cannot be a class) = with a single string (of variable length, 0+). >>=20 >> In /etc/networks.subr you can see an example usage of ltr: >>=20 >> 287 = = _punct=3D".-/+" >> 288 = = ltr ${_if} "${_punct}" '_' _if >>=20 >>=20 >> The result of this is to take a value of (for example) foo.bar and = replace >> any occurrences of period, minus, forward slash, or plus with instead >> a single underscore. The result is stuffed into the variable = =E2=80=9C_if=E2=80=9D (over- >> writing previous contents which may have contained aforementioned >> characters replaced with underscore). >>=20 >> An attempt to use ltr in the below fashion: >>=20 >> ltr $string =E2=80=98[:lower:]=E2=80=99 =E2=80=98[:upper:]=E2=80=99 = somevar >>=20 >> would surely fail. >>=20 >> While it is indeed *possible* to write a find/replace function in = native- >> shell that supports character classes, it would not be a small = function. >> The primary issue is that you need to know what the character that >> matched the class and there aren=E2=80=99t any built-ins that provide = this info. >>=20 >> For example: >>=20 >> case =E2=80=9C$src=E2=80=9D in *[[:lower:]]*) >>=20 >> will trigger when you have a lower-case character that needs = conversion >> to upper-case (or opposite if using *[[:upper:]]*) BUT you won=E2=80=99= t know >> what the character was that you matched (so how can you know which >> upper-case character to supplant)? >>=20 >> The function will have to resort to complicated substring mechanics = or >> any other seldom known procedure. >>=20 >> I=E2=80=99ll have a noodle on it and see what I can come up with. = It=E2=80=99s not exactly >> immediately coming to me how to do this in any simple fashion while >> maintaining efficiency (read: by not iterating over every single = character >> and also by not having a giant massive case statement with every = letter >> spelled out =E2=80=94 coming up with a solution that embraces the use = of the >> character class I would believe to be more efficient). >=20 > John Baldwin suggested "dd conv=3Dlcase", since dd is in /bin. >=20 > $ echo MixedCaseLetters | dd conv=3Dlcase 2>/dev/null > mixedcaseletters >=20 > $ type dd > dd is /bin/dd >=20 Yeah, I have to say, this looks by far the simplest approach. Even if I or Colin or someone else were to whip up a comprehensive native shell function that does this, I can=E2=80=99t say that it would = be chosen necessarily over the dd approach (which itself is comprehensive but may suffer the lag of pulling dd into memory =E2=80=94 most significant = when say, running off of CD). Not knowing where the code is destined nor how many times iteratively it could be passed over in a casual day, it=E2=80=99s still probably likely that the dd approach is the best = (unless you=E2=80=99re doing it repetitively in a tight loop ;D). =E2=80=94=20 Devin