On 25-11-2008 16:15:09 -0800, Ned Ludd wrote:
> On Tue, 2008-11-25 at 18:05 +0200, Amit Dor-Shifer wrote:
> > Given the following:
> > # qlist -Iv sys-apps/portage
> > sys-apps/portage-2.1.4.5
> > 
> > How do I safely extract the "2.1.4.5"?
> > 
> > (I don't necessarily need to use qlist. Just want to get the version of 
> > an installed package within a bash script)
> 
> qatom $(qlist -ICv sys-apps/portage) | awk '{print $3}'

I happen to do it in bash for my update script, it hasn't broke yet:

get_ebuildversion() {
    if [[ -z $1 ]] ; then
        return
    fi

    # strip extension
    t=${1%.ebuild}
    # abort if this is not an ebuild
    if [[ $t == $1 ]] ; then
        return
    fi
    # strip package name
    t=${t#*-}
    # sometimes there are dashes in the package name
    while [[ ${t:0:1} < "0" || ${t:0:1} > "9" ]] ; do
        [[ $t != ${t#*-} ]] \
            && t=${t#*-} \
            || break
    done

    echo ${t}
}

you might want to remove the .ebuild check and strip the category ($1#*/})


-- 
Fabian Groffen
Gentoo on a different level

Reply via email to