[GRASS-dev] Use g.tempfile

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?

Thank in advanced

R

On Feb 6, 2008 4:23 PM, roberto marzocchi <roberto.marzocchi@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 :slight_smile: 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

Markus Neteler wrote:

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

# get full path temp file
temp1="`g.tempfile pid=$$`"

actually, I am not so sure the extra "quotes" are really needed around
the `back quotes`. (But I don't think they hurt anything)

e.g.
$ FOO="a b"
$ BAR=`echo $FOO`
$ echo $BAR
a b

Hamish

      ____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping