[GRASS-dev] Use g.tempfile

Markus Neteler neteler at osgeo.org
Wed Feb 6 10:32:32 EST 2008


On Feb 6, 2008 4:23 PM, roberto marzocchi <roberto.marzocchi at gmail.com> wrote:
> I have a question about use of g.tempfile
>  if I  want to create  a  temporary file in a script I've to write:
>  temp1=`g.tempfile pid=$$`
>
> and then I've to use this file e.g. :
>
>
>  r.out.ascii -h input=dtm output="$temp1" null=0
>
>  Is correct?

Nearly :) Note the quotes to prevent from white space issues in the path:

# get full path temp file
temp1="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$temp1" ] ; then
    g.message -e "Unable to create temporary files"
    exit 1
fi

r.out.ascii -h input=dtm output="$temp1" null=0

Note that you then find the result in
GRASSDATA/LOCATION/MAPSET/.tmp/HOSTNAME/file

which is possibly not the best place *if* you want to give the
file to someone. If you continue to use it internally in your
script, it is just fine.

Before closing the script, you should "rm" the file.
See existing GRASS scripts for inspiration.

Markus

Markus


More information about the grass-dev mailing list