From owner-freebsd-rc@FreeBSD.ORG Sat Nov 6 01:30:32 2010 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B1E2F106566B for ; Sat, 6 Nov 2010 01:30:32 +0000 (UTC) (envelope-from cyrille.lefevre-lists@laposte.net) Received: from out1.laposte.net (out2.laposte.net [193.251.214.119]) by mx1.freebsd.org (Postfix) with ESMTP id 433C18FC0C for ; Sat, 6 Nov 2010 01:30:31 +0000 (UTC) Received: from meplus.info (localhost [127.0.0.1]) by mwinf8213.laposte.net (SMTP Server) with ESMTP id 825327000091; Sat, 6 Nov 2010 02:30:30 +0100 (CET) Received: from [192.168.1.133] (162.64.99-84.rev.gaoland.net [84.99.64.162]) by mwinf8213.laposte.net (SMTP Server) with ESMTP id 0AEC27000089; Sat, 6 Nov 2010 02:30:27 +0100 (CET) X-ME-UUID: 20101106013028448.0AEC27000089@mwinf8213.laposte.net Message-ID: <4CD4B040.1000804@laposte.net> Date: Sat, 06 Nov 2010 02:32:48 +0100 From: Cyrille Lefevre Organization: ACME User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070326 Thunderbird/2.0.0.0 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Devin Teske References: <1286925182.32724.18.camel@localhost.localdomain> <1286996709.32724.60.camel@localhost.localdomain> <1287448781.5713.3.camel@localhost.localdomain> <1287510629.25599.2.camel@localhost.localdomain> <1288746388.7362.4.camel@localhost.localdomain> <17B64023-A64A-40DA-9CBC-A601710AB5BB@vicor.com> <1288919368.7362.35.camel@localhost.localdomain> <4CD3731C.6020501@laposte.net> <1288978858.7362.154.camel@localhost.localdomain> In-Reply-To: <1288978858.7362.154.camel@localhost.localdomain> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-me-spamlevel: not-spam X-me-spamrating: 30.000000 X-me-spamcause: OK, (-250)(0000)gggruggvucftvghtrhhoucdtuddrfedtiedrtdekucetggdotefuucfrrhhofhhilhgvmecuoehnohhnvgeqnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucdlqddutddtmdenfhhunhgtthhiohhnqegsvghgihhnqegvnhguucdlqdehtddm Cc: freebsd-rc@freebsd.org Subject: Re: sysrc(8) -- a sysctl(8)-like utility for managing rc.conf(5) X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Nov 2010 01:30:32 -0000 Le 05/11/2010 18:40, Devin Teske a =E9crit : > On Fri, 2010-11-05 at 03:59 +0100, Cyrille Lefevre wrote: >> Le 05/11/2010 02:09, Devin Teske a =E9crit : you don't have to comment every line w/ 10+ lines of comments. I don't agress you, it was just a proposal which is IMHO more readable. however, it's your code and you make whatever you want w/ it. the more important thing is that you understand it, well, except if someone else have to maintain it also :-) >> awkscript=3D' >> # %s/\\$0/$0/;s/\\\\/\\/g >> BEGIN { ...; regex=3D"^[[:space:]]*" varname "=3D" } >=20 > Won't work. >=20 > The point of failure here is that you've taken $varname (which is a > positional parameter passed to the shell script function) and turned it= > into an awk variable (which is never assigned). you're wrong, the assignment is done later in : awk -v varname=3D"$varname" ... "$awkscript" > So right off the bat, your awk script will fail because regex will be > assigned a value of: >=20 > ^[[:space:]]*=3D wrong too, $ v=3D123; awk -v v=3D"$v" 'BEGIN{ r=3D"^[[:space:]]*"v"=3D"; print r; ex= it}' ^[[:space:]]*123=3D >> ... >> if ( t1 ~ /[\'\$\\]/ ) >=20 > Since we're picking nits: > - the backslash before the apostrophe is not needed. right :-) >> ... >> else if ( t1 =3D=3D apos ) { >=20 > apos needs to be a shell-expanded parameter/variable, otherwise you'll > be forced to declare apos in the awkscript, which itself (without using= > compound strings) will force vim syntax highlighting to break (somethin= g > that's not really important for the awkscript itself, but it's rather > disconcerting to see entire oceans of miscolored text AFTER the embedde= d > here-document). done in awk -v apos=3D"'" ... "$awkscript" below >> ... >> else if ( t1 ~ /[[:space:]];#]/ ) >> # parentheses aren't needed here, or wrap them as before >> t1 =3D t2 =3D "\"" bad copy/paste, I was talking about the later one (null assignment) # Null-assignment else if ( t1 ~ /[[:space:]];#]/ ) { t1 =3D t2 =3D "$bquot" } should be # Null-assignment else if ( t1 ~ /[[:space:]];#]/ ) { t1 =3D t2 =3D "$bquot" } to look like above syntax. >> ... >> printf "%s%c%s%c%s\n", substr(\$0, 0, matchlen), \ >> t1, awk_new_value, t2, value >> ' >=20 > Just as before with $regex (which had $varname which is $1 which is the= > positional parameter passed to the shell function), this will fail > because awk_new_value is not defined by awk. see below too ;^) > Further, you've forgotten to conver \$0 to $0 (considering that you've no, look at the # %s/\\$0/$0/;s/\\\\/\\/g abobe >> # ... | ... doesn't need a final \ when wrapped after the | >> local awk_new_value=3D"$( echo "$new_value" | >> awk '{ gsub(/\\/, "\\\\"); gsub(/"/, "\\\""); print }' )" >=20 > Wrong. Fail. And here's why... >=20 > You are correct that a $( ... ) block can traverse newlines. >=20 > However, what $( ... ) functional performs is a sub-shell. Each line > within the $( ... ) syntax is taken as a single-line of shell to be > executed. >=20 > Therefore, by deleting the back-slash at the end of the line, you've > turned one statement into two. no, no, no, did you tried it ? your syntax : x=3D$(echo x \ | sed s,x,y,) echo $x the usual syntax : x=3D$(echo x | sed s,x,y,) echo $x both should print y or the shell is buggy ? so, as I told you, the \ isn't needed after a |. >> # you missed the " here >> new_contents=3D$( tail -r "$file" 2> /dev/null ) >=20 > No, I did not. And here's why... I was talking about the ones around $file, not the ones around $() >> # you may want to use printf "%s" "$new_contents" instead of echo >> # to avoid \ sequences interpretation if any >> new_contents=3D$( echo "$new_contents" | >> awk -v varname=3D"$varname" -v apos=3D"'" \ >> -v new_value=3D"$new_value" "$awkscript") when I'll have time, I'll try my code against your code to see the differences and if there is so many bad effects ? >> also, %s|/bin/sh|$_PATH_BSHELL| && _PATH_BSHELL=3D/bin/sh it's just an habit to hardcode path within variables and a proposal. > Not sure where you got the bquotquot (not in my code). in my example, the %s/quot/dquot/ statment turns bquot to bquotquot :-) > perl(1)). You cannot perform multiple '%s///' operators separated by a > semi-colon. You would get the error "E488: Trailing characters" in vim it was just a synthetic form of writing, no more. Regards, Cyrille Lefevre --=20 mailto:Cyrille.Lefevre-lists@laposte.net