From owner-svn-src-all@FreeBSD.ORG Mon May 11 19:44:40 2015 Return-Path: Delivered-To: svn-src-all@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 6A2D14D2; Mon, 11 May 2015 19:44:40 +0000 (UTC) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [199.48.133.146]) by mx1.freebsd.org (Postfix) with ESMTP id 367B510C8; Mon, 11 May 2015 19:44:39 +0000 (UTC) Received: from marvin.lab.vangyzen.net (c-73-147-253-17.hsd1.va.comcast.net [73.147.253.17]) by smtp.vangyzen.net (Postfix) with ESMTPSA id 75E2356467; Mon, 11 May 2015 14:44:32 -0500 (CDT) Message-ID: <555106B5.3010104@FreeBSD.org> Date: Mon, 11 May 2015 15:44:53 -0400 From: Eric van Gyzen User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Devin Teske , Brooks Davis CC: John Baldwin , Xin LI , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Subject: Re: svn commit: r282672 - head/etc/rc.d References: <201505082336.t48NaWRS080408@svn.freebsd.org> <20150511191850.GC68045@spindle.one-eyed-alien.net> <9FB76653-EF89-48E5-B4E8-A2006923B76A@FreeBSD.org> In-Reply-To: <9FB76653-EF89-48E5-B4E8-A2006923B76A@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 May 2015 19:44:40 -0000 On 05/11/2015 15:37, Devin Teske wrote: > >> On May 11, 2015, at 12:18 PM, Brooks Davis > wrote: >> >> On Sun, May 10, 2015 at 03:45:48PM -0400, John Baldwin wrote: >>> >>>> On May 8, 2015, at 19:36, Xin LI > wrote: >>>> >>>> Author: delphij >>>> Date: Fri May 8 23:36:31 2015 >>>> New Revision: 282672 >>>> URL: https://svnweb.freebsd.org/changeset/base/282672 >>>> >>>> Log: >>>> Always convert uuid to lower case. >>>> >>>> MFC after: 2 weeks >>>> >>>> Modified: >>>> head/etc/rc.d/hostid >>>> >>>> Modified: head/etc/rc.d/hostid >>>> ============================================================================== >>>> --- 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() >>>> >>>> valid_hostid() >>>> { >>>> - uuid=$1 >>>> + uuid=$(echo $1 | tr '[:upper:]' '[:lower:]') >>> >>> tr is in /usr/bin so this breaks systems with a separate /usr. Perhaps you could use dd with conv=lcase instead? >> >> Alterntively, a shell function "ltr" exists in rc.subr for this purpose. >> > > ltr would not work in this situation, for multiple reasons. > > 1. ltr doesn’t support character classes > 2. ltr is for replacing one or more characters (cannot be a class) with a single string (of variable length, 0+). > > In /etc/networks.subr you can see an example usage of ltr: > > 287 _punct=".-/+" > 288 ltr ${_if} "${_punct}" '_' _if > > > 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 “_if” (over- > writing previous contents which may have contained aforementioned > characters replaced with underscore). > > An attempt to use ltr in the below fashion: > > ltr $string ‘[:lower:]’ ‘[:upper:]’ somevar > > would surely fail. > > 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’t any built-ins that provide this info. > > For example: > > case “$src” in *[[:lower:]]*) > > will trigger when you have a lower-case character that needs conversion > to upper-case (or opposite if using *[[:upper:]]*) BUT you won’t know > what the character was that you matched (so how can you know which > upper-case character to supplant)? > > The function will have to resort to complicated substring mechanics or > any other seldom known procedure. > > I’ll have a noodle on it and see what I can come up with. It’s 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 — coming up with a solution that embraces the use of the > character class I would believe to be more efficient). John Baldwin suggested "dd conv=lcase", since dd is in /bin. $ echo MixedCaseLetters | dd conv=lcase 2>/dev/null mixedcaseletters $ type dd dd is /bin/dd Eric