[GRASS-dev] g.mremove bug?

Ivan Shmakov ivan at theory.asu.ru
Thu Feb 21 23:40:10 EST 2008


>>>>> Glynn Clements <glynn at gclements.plus.com> writes:

 >> $ g.mlist rast pattern="out_ST*" | sed -e s/^/rast=/ | xargs g.remove

 >> This variant runs `g.remove' in ``batches'', supplying each time
 >> just enough arguments to reasonably fill the limited command line
 >> space.

 >> The use of `xargs' is safe as long as the arguments don't contain
 >> any of the following characters:

[...]

 > That isn't a problem; GRASS map names aren't allowed to contain any
 > of those characters.

	ACK, thanks.

 > The more fundamental problem with using xargs is that the GRASS
 > parser requires multiple "answers" for any given option to be
 > separated by commas, not spaces.

	Does it?  IIUC, the following commands are completely equivalent
	as long as the GRASS parser is concerned:

$ g.remove rast=foo,bar 

$ g.remove rast=foo rast=bar 

 > That effectively requires g.mremove to collate names itself.

 > Invoking g.remove once per map is simpler, but it's also inefficient.

	Huh?  Even simpler than the following?

may_be_foo () {
    if [ -z "$2" ]; then
        ## .
        return
    fi
    g.mlist $regex type="$1" mapset="$MAPSET" pattern="$2" \
        | sed -e s,^,"$1"=,
}

{
    may_be_foo rast   "$r"
    may_be_foo rast3d "$r3"
    may_be_foo vect   "$v"
    may_be_foo icon   "$i"
    may_be_foo labels "$l"
    may_be_foo region "$rg"
    may_be_foo group  "$g"
    may_be_foo 3dview "$d"
} | xargs g.remove

	But actually, since POSIX `xargs' lacks `-r', it's necessary to
	check for the empty list case, e. g.:

{
    ...
} > "$tmp"

if grep -q . -- "$tmp"; then
    xargs g.remove < "$tmp"
fi



More information about the grass-dev mailing list