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:

# GRASS session variables
GRASSLOC="4326" # This is the EPSG code of the CRS used

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

# 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.

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?

1 Answer 1


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. Commented Jun 21, 2018 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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