Batch module. Define/Change name of main script files

In the second example in the batch docs a lots of maps of each country of Europe are created with the main script (and then combine into a single pdf).

The names of the files created by the main script are countries_01.pdf. How can I change it to the country name? I.e, change countries_01.pdf to Andorra.pdf and so on with the other 50 files. Can it be done with GMT? Or should I use an external tool?

I guess in, before the begin you could have a line like

line=$(echo $BATCH_NAME | awk -F[-.] '{print $1'})
name=$(awk -v var=$line 'NR==var {print $3}' countries.txt)

gmt begin $name png


Maybe just use gmt begin ${BATCH_WORD1} pdf instead of BATCHNAME?

No, I tried to change the BATCH_NAME but I get an error.
mv: no se puede efectuar stat’ sobre ‘countries_48.*’: No existe el archivo o el directorio`

And in the docs says

Note: Any product(s) made by the processing scripts should be named using BATCH_NAME as their name prefix as these will be automatically moved up to the starting directory upon completion.

So I think I should do it in the postflight script.

Or even after the script ? In a loop with mv and the little piece a code above ?

Thanks, yes postflight is the logical place.

Using this in the post file works, and I am not deleting the individual files:

awk -F'\t' '{printf "mv countries_%2.2d.pdf \"%s.pdf\"\n", NR-1, \$2}' ../../countries.txt | sh -s

Thanks. I had to modify a bit your command to find countries.txt
awk -F'\t' '{printf "mv countries_%2.2d.pdf \"%s.pdf\"\n", NR-1, \$2}' \${BATCH_PREFIX}/countries.txt | sh -s