From owner-freebsd-rc@FreeBSD.ORG Fri Nov 5 03:18:00 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 0968C1065673 for ; Fri, 5 Nov 2010 03:18:00 +0000 (UTC) (envelope-from cyrille.lefevre-lists@laposte.net) Received: from out6.laposte.net (out5.laposte.net [193.251.214.122]) by mx1.freebsd.org (Postfix) with ESMTP id 91E3D8FC0A for ; Fri, 5 Nov 2010 03:17:59 +0000 (UTC) Received: from out5.laposte.net (unknown [10.98.51.225]) by mwinf8405.laposte.net (SMTP Server) with ESMTP id 564B41C0014B for ; Fri, 5 Nov 2010 03:57:32 +0100 (CET) Received: from meplus.info (localhost [127.0.0.1]) by mwinf8412.laposte.net (SMTP Server) with ESMTP id 3356AE000097; Fri, 5 Nov 2010 03:57:30 +0100 (CET) Received: from [192.168.1.133] (162.64.99-84.rev.gaoland.net [84.99.64.162]) by mwinf8412.laposte.net (SMTP Server) with ESMTP id D550EE000094; Fri, 5 Nov 2010 03:57:24 +0100 (CET) X-ME-UUID: 20101105025725873.D550EE000094@mwinf8412.laposte.net Message-ID: <4CD3731C.6020501@laposte.net> Date: Fri, 05 Nov 2010 03:59:40 +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> In-Reply-To: <1288919368.7362.35.camel@localhost.localdomain> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable X-me-spamlevel: not-spam X-me-spamrating: 36.000000 X-me-spamcause: OK, (-100)(0000)gggruggvucftvghtrhhoucdtuddrfedtiedrtdejucetggdotefuucfrrhhofhhilhgvmecuoehnohhnvgeqnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd 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: Fri, 05 Nov 2010 03:18:00 -0000 Le 05/11/2010 02:09, Devin Teske a =E9crit : hi, how about something like (untested, but should work) : # no $(cat << EOF needed here, so, no extra \ and $quot and so needed awkscript=3D' # %s/\\$0/$0/;s/\\\\/\\/g BEGIN { ...; regex=3D"^[[:space:]]*" varname "=3D" } =2E.. if ( ! match($0, regex) ) { print; next } =2E.. if ( t1 ~ /[\'\$\\]/ ) =2E.. else if ( t1 =3D=3D apos ) { sub("^" apos "[^" apos "]*", "", value) if ( length(value) =3D=3D 0 ) t2 =3D "" sub("^" apos, "", value) =2E.. else if ( t1 =3D=3D "\"" ) { sub(/^"[^"]*/, "", value) if ( length(value) =3D=3D 0 ) t2 =3D "" sub(/^"/, "", value) =2E.. t1 =3D t2 =3D "\"" =2E.. else if ( t1 ~ /[[:space:]];#]/ ) # parentheses aren't needed here, or wrap them as before t1 =3D t2 =3D "\"" =2E.. printf "%s%c%s%c%s\n", substr(\$0, 0, matchlen), \ t1, awk_new_value, t2, value ' # ... | ... doesn't need a final \ when wrapped after the | local awk_new_value=3D"$( echo "$new_value" | awk '{ gsub(/\\/, "\\\\"); gsub(/"/, "\\\""); print }' )" =2E.. # you missed the " here new_contents=3D$( tail -r "$file" 2> /dev/null ) # 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") of course, same remarks about the later awk script :-) also, %s|/bin/sh|$_PATH_BSHELL| && _PATH_BSHELL=3D/bin/sh PS : for non french user : %s/quot/dquot/;%s/apos/squot/;s/bquotquot/bquot/ Regards, Cyrille Lefevre --=20 mailto:Cyrille.Lefevre-lists@laposte.net