0

This is a follow up to a previous question on the creation of GRASS locations from a bash script.

Having successfully created a location, I would now like to create a new mapset within this location. The script looks like this:

#!/bin/sh
# GRASS session variables
GRASSDB="/tmp/grassdata"
GRASSLOC="4326" # This is the EPSG code of the CRS used
GRASSMAP="comparison"

# path to GRASS binaries and libraries:
export GISBASE=/usr/lib/grass74
export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib


# Create GRASS database folder
mkdir -p "$GRASSDB"

# Create a new GRASS location
echo "==== Creating new GRASS location ===="
grass74 -c -e "epsg:$GRASSLOC" "$GRASSDB/$GRASSLOC"

echo "==== Creating new mapset ===="
grass74 -c -e "$GRASSDB/$GRASSLOC/$comparison"

It produces the following output:

$ sh comparison.sh 
==== Creating new GRASS location ====
Cleaning up temporary files...
Creating new GRASS GIS location/mapset...
Cleaning up temporary files...
==== Creating new mapset ====
Cleaning up temporary files...
Creating new GRASS GIS location/mapset...
ERROR: Failed to create new location. The location <4326> already exists.
Exiting...

Unlike what is described in the wiki, the -c argument always attempts to create a new location, and not just a mapset. How can I create just a mapset within an existing location?

3

Your the $comparison doesn't have a value so it evaluates to nothing.

Thus your grass74 -c -e "$GRASSDB/$GRASSLOC/$comparison"

evaluates to

grass74 -c -e "$GRASSDB/$GRASSLOC/"

which already was made in the previous step.

To tell Bash to raise an error if expands an empty variable write in your top of your script

set -u

  • Blimey! That was a stupid mistake. – Luís de Sousa Jun 21 '18 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.