svcprop(1) does a pretty heroic job of escaping shell metachars from
property values.  It's even heroic about newlines in property values

Unfortunately the way it deals with multiple values ruins that heroism:

% svcprop -t -c -p config someservice
config/bar astring d\
\ c e
% 

Quick: how many values is that?

In my case it was *two*.  Bet you couldn't tell.

I'd rather svcprop(1) had an option to print multiple values like so:

% svcprop -m -c -p config someservice
config/bar astring d\
\ c
config/bar astring e
% 

What say ye?  I'll file the fasttrack and implement it even.


BTW, in ksh (93, but this can be trivially adapted to 88) one could then
easily deal with this output via a function like:

function readprop {
        typeset cont line pg pgvar prop propvar typ typevar value valvar

        read -r prop typ value || return $?

        typeset -n pgvar=${prop%/*}
        pgvar=()
        typeset -n propvar=pgvar.${prop#*/}
        propvar=()
        typeset -n typvar=propvar.typ
        typeset -n valvar=propvar.val[${#propvar.v...@]}]

        typvar=$typ
        valvar=

        [[ "$value" = *[!\\]\\ ]] || return 0
        value=${value%\\}

        valvar=$value

        cont=:
        while $cont
        do
                read -r line || return $?

                if [[ "$line" = *[!\\]\\ ]]
                then
                        line=${line%\\}
                else
                        cont=false
                fi

                if [[ -z "$propvar" ]]
                then
                        valvar="$line"
                else
                        valvar+="
$line"
                fi
        done

        return 0
}

(Yes, Roland can probably trim that doesn quite a bit.)

% print "config/foobar astring foo\\^Jbar"|readprop
% print "config/foobar astring does it\\^Jwork?"|readprop
% print -r -- "${config.foobar}"
(
        typ=astring
        typeset -a val=(
                $'foo\nbar'
                $'ick\nick'
                $'does it\nwork?'
        )
)
% 

All that's missing is the new option for svcprop(1) mentioned above.

Nico
-- 

Reply via email to