From owner-freebsd-rc@FreeBSD.ORG Sat Nov 6 14:34:42 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 BAB431065673 for ; Sat, 6 Nov 2010 14:34:42 +0000 (UTC) (envelope-from cyrille.lefevre-lists@laposte.net) Received: from out3.laposte.net (out4.laposte.net [193.251.214.121]) by mx1.freebsd.org (Postfix) with ESMTP id 4E0B08FC0C for ; Sat, 6 Nov 2010 14:34:41 +0000 (UTC) Received: from meplus.info (localhost [127.0.0.1]) by mwinf8316.laposte.net (SMTP Server) with ESMTP id 9084A7000095; Sat, 6 Nov 2010 15:34:40 +0100 (CET) Received: from [192.168.1.133] (162.64.99-84.rev.gaoland.net [84.99.64.162]) by mwinf8316.laposte.net (SMTP Server) with ESMTP id 4C1A4700008D; Sat, 6 Nov 2010 15:34:38 +0100 (CET) X-ME-UUID: 20101106143439311.4C1A4700008D@mwinf8316.laposte.net Message-ID: <4CD56812.8080502@laposte.net> Date: Sat, 06 Nov 2010 15:37:06 +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> <4CD4B040.1000804@laposte.net> <1289013402.7362.282.camel@localhost.localdomain> In-Reply-To: <1289013402.7362.282.camel@localhost.localdomain> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-me-spamlevel: not-spam X-me-spamrating: 30.799999 X-me-spamcause: OK, (-230)(0000)gggruggvucftvghtrhhoucdtuddrfedtiedrtdelucetggdotefuucfrrhhofhhilhgvmecuoehnohhnvgeqnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucdlqddutddtmdenfhhrvggvsghsugdvgiculddqvddtmdenuefuffculddquddtmd 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 14:34:42 -0000 Le 06/11/2010 04:16, Devin Teske a =C3=A9crit : > On Sat, 2010-11-06 at 02:32 +0100, Cyrille Lefevre wrote: >> Le 05/11/2010 18:40, Devin Teske a =C3=A9crit : >>> On Fri, 2010-11-05 at 03:59 +0100, Cyrille Lefevre wrote: >>>> Le 05/11/2010 02:09, Devin Teske a =C3=A9crit : > Ah, I was also confused by "parentheses" -- I've always referred to > those as braces (of the "curly" persuasion). well, english isn't my natural language, so, sometimes, I used the wrong word... :-) >>>> # ... | ... doesn't need a final \ when wrapped after the | >>>> local awk_new_value=3D"$( echo "$new_value" | >>>> awk '{ gsub(/\\/, "\\\\"); gsub(/"/, "\\\""); print }' )" >>> >>> Wrong. Fail. And here's why... >>> >>> You are correct that a $( ... ) block can traverse newlines. >>> >>> However, what $( ... ) functional performs is a sub-shell. Each line >>> within the $( ... ) syntax is taken as a single-line of shell to be >>> executed. >>> >>> 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 |. >=20 > no, no, no, did YOU try it? well, you're not undertandnig me, again :-) I am talking about putting the pipe to the end of the first line, not to the begin of following the line. your examples doesn't show this case, so, try it again :-) > In this case, I argue that I don't need quotes around $file, because th= e > operating system itself (as you can see above; notably lines 1, 3, 7 an= d > 8) does not support values of rc_conf_files that contain spaces. may be the operating system is wrong :-) it's a usual habit to protect everything (files, parameters, etc) w/ " in case of spaces except the exception where you want to do word splitting, which is a rare case finally. also, it is to be concistent w/ the rest of the script where evrery occurence of a file is " protected, so, why not here ! in this case, why do you protect $tmpfile which is generated bu mktemp (probably w/o spaces), etc. >>>> # you may want to use printf "%s" "$new_contents" instead of echo >>>> # to avoid \ sequences interpretation if any about echo vs printf : echo 'x\tx' =3D> x x vs printf '%s' "x\tx' =3D> x\tx the usual problem is that printf isn't a builtin, this imply performance degradation... alternatively, you may want to use the -E option to echo if supported (freebsd seems to support it, so, use it). same remark about read, always use the -r option... for the history, echo is one of the more unportable command of the unix universe ! http://www.in-ulm.de/~mascheck/various/echo+printf/ > Make sure you use bourne-shell for your tests. >=20 > No shell system-level scripts within FreeBSD use bash (and rightly so, > as it's not part of the base distribution). I'm not talking bash in any case, I hate bash for many reasons, ksh is one of the best shell, except maybe zsh, but I don't know this one, but I'm talking posix shell w/o any problem :-) > Well... I have to say thank you. >=20 > I'm somewhat new to marrying awk(1) w/ sh(1). I do have to say that `-v= > key=3Dvalue' is very handy! >=20 > The most important thing is that this now allows me to assign the > literal awkscript to a variable outside the function, meaning that the > script doesn't need to be regenerated everytime the function is called.= > Essentially performing a caching of sorts. This should further enhance > the performance of my script -- thanks! you're welcome. Regards, Cyrille Lefevre --=20 mailto:Cyrille.Lefevre-lists@laposte.net