[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: better init.d/* : who carres ?



Marc Chantreux <marc.chantreux@ulpmm.u-strasbg.fr> writes:

> there are a lot of things in /etc/init.d/*, and {pre,post}inst scripts
> that can be rewritten more efficiently ( i think ).

> for example, in /etc/init.d/mysqld

> mysqld_get_param() {
>         /usr/sbin/mysqld --print-defaults \
>                 | tr " " "\n" \
>                 | grep -- "--$1" \
>                 | tail -n 1 \
>                 | cut -d= -f2
> }

> can be written like :

> mysqld_get_param () {
>     local string=$( /usr/sbin/mysqld --print-defaults | grep -o -- "--$1=[^ ]*" )
>     echo ${string#*=}
> }

> that are not bugs so i wonder if package maintainers where pleased if i
> reportbug those lines as wishlist.

It would certainly be fine for me to get wishlist bugs of this sort
against my packages, although in this particular case I would probably
close the bug with the explanation that I find the first form easier to
read and don't think the efficiency difference is particularly important.

I find constructs like ${string#*=} particularly difficult to read, since
they require that I remember what all the different punctuation characters
inside this sort of parameter expansion do.  According to the bash manual,
there are sixteen of them, and I had to read the description of
${parameter#word} three times before I completely understood what it said.

The advantage of the original form is that each one of those lines is
doing something very simple and straightforward.  Yes, you have to
understand the function of four different programs, but each of those four
programs are considerably simpler than sed or awk and the ways in which
they're being used are very common ones.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>



Reply to: