Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 06 Nov 2010 15:37:06 +0100
From:      Cyrille Lefevre <cyrille.lefevre-lists@laposte.net>
To:        Devin Teske <dteske@vicor.com>
Cc:        freebsd-rc@freebsd.org
Subject:   Re: sysrc(8) -- a sysctl(8)-like utility for managing rc.conf(5)
Message-ID:  <4CD56812.8080502@laposte.net>
In-Reply-To: <1289013402.7362.282.camel@localhost.localdomain>
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>	 <D763F474-8F19-4C65-B23F-78C9B137A8FE@vicor.com>	 <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>

next in thread | previous in thread | raw e-mail | index | archive | help

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





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4CD56812.8080502>