<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FOsfraid</id>
	<title>GRASS-Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FOsfraid"/>
	<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/wiki/Special:Contributions/%E2%9A%A0%EF%B8%8FOsfraid"/>
	<updated>2026-05-25T22:05:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Working_with_GRASS_without_starting_it_explicitly&amp;diff=21422</id>
		<title>Working with GRASS without starting it explicitly</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Working_with_GRASS_without_starting_it_explicitly&amp;diff=21422"/>
		<updated>2015-03-20T15:45:38Z</updated>

		<summary type="html">&lt;p&gt;⚠️Osfraid: /* Python: GRASS GIS 7 with existing location */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;GRASS modules and imports of GRASS Python packages works only in a specific environmental settings (GRASS session). This settings is ensured by starting GRASS GIS application which prepares this GRASS session for you. It is possible to set up you system in the way GRASS session will be always active (GRASS is not running, just the environmental settings is ready). People often prefer to set up the GRASS environment in their script or program and this is what this article discuss. However, it must be noted that the the generally preferred (and easy) way is to create scripts and programs as GRASS modules which means that your don't have to bother with setting up the environment since the GRASS module should be always invoked only in GRASS session.&lt;br /&gt;
&lt;br /&gt;
== GRASS sessions ==&lt;br /&gt;
&lt;br /&gt;
It is possible to access GRASS modules without explicitly starting a &amp;quot;GRASS session&amp;quot;. GRASS libraries require certain [http://grass.osgeo.org/grass70/manuals/variables.html environment variables] to be set. In fact a &amp;quot;GRASS session&amp;quot; is just a set of processes (e.g. a shell and/or GUI) which have the necessary environment settings, specifically:&lt;br /&gt;
&lt;br /&gt;
* '''GISBASE''' needs to be set to the top-level directory of the GRASS installation.&lt;br /&gt;
* '''GISRC''' needs to contain the absolute path to a file containing settings for '''GISDBASE''', '''LOCATION_NAME''' and '''MAPSET'''.&lt;br /&gt;
* '''PATH''' needs to include '''$GISBASE/bin''' and '''$GISBASE/scripts'''.&lt;br /&gt;
&lt;br /&gt;
If the GRASS libraries are shared libraries, the loader needs to be able to find them. This normally means that '''LD_LIBRARY_PATH''' (Linux, Solaris), '''DYLD_LIBRARY_PATH''' (MacOSX) or '''PATH''' (Windows) need to contain '''$GISBASE/lib''', although there are other means to the same end (e.g. on Linux, putting $GISBASE/lib (with $GISBASE replaced by its actual value) into /etc/ld.so.conf then running ldconfig).&lt;br /&gt;
&lt;br /&gt;
Some libraries and modules use other variables. More information for most of them is available in the file ''$GISBASE/docs/html/variables.html''. The display libraries used by ''d.*'' commands use additional variables, which are documented along with the individual drivers.&lt;br /&gt;
&lt;br /&gt;
=== Batch jobs ===&lt;br /&gt;
&lt;br /&gt;
You can run GRASS scripts non-interactively from outside of a GRASS session with the GRASS_BATCH_JOB environment variable. When GRASS is started with this environment variable set it will automatically run the contents of the script given in the variable, then close the GRASS session when complete. In this way full lock-checking, GRASS variables setup, and temporary file cleaning tasks are still performed.&lt;br /&gt;
&lt;br /&gt;
See the [[GRASS_and_Shell#GRASS_Batch_jobs|Batch jobs]] section of the GRASS shell-help wiki page for details.&lt;br /&gt;
&lt;br /&gt;
=== Accessing GRASS modules without starting a GRASS session ===&lt;br /&gt;
&lt;br /&gt;
==== Python examples ====&lt;br /&gt;
&lt;br /&gt;
See also [[GRASS Python Scripting Library]]&lt;br /&gt;
&lt;br /&gt;
===== Python: GRASS GIS 7 with existing location =====&lt;br /&gt;
&lt;br /&gt;
The script initializes the session and lists available raster and vector maps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
import subprocess&lt;br /&gt;
&lt;br /&gt;
# path to the GRASS GIS launch script&lt;br /&gt;
# MS Windows&lt;br /&gt;
grass7bin_win = r'C:\OSGeo4W\bin\grass70svn.bat'&lt;br /&gt;
# uncomment when using standalone WinGRASS installer&lt;br /&gt;
# grass7bin_win = r'C:\Program Files (x86)\GRASS GIS 7.0.0beta3\grass70.bat'&lt;br /&gt;
# Linux&lt;br /&gt;
grass7bin_lin = 'grass70'&lt;br /&gt;
# Mac OS X&lt;br /&gt;
# this is TODO&lt;br /&gt;
grass7bin_mac = '/Applications/GRASS/GRASS-7.0.app/'&lt;br /&gt;
&lt;br /&gt;
# DATA&lt;br /&gt;
# define GRASS DATABASE&lt;br /&gt;
# add your path to grassdata (GRASS GIS database) directory&lt;br /&gt;
gisdb = os.path.join(os.path.expanduser(&amp;quot;~&amp;quot;), &amp;quot;grassdata&amp;quot;)&lt;br /&gt;
# the following path is the default path on MS Windows&lt;br /&gt;
# gisdb = os.path.join(os.path.expanduser(&amp;quot;~&amp;quot;), &amp;quot;Documents/grassdata&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# specify (existing) location and mapset&lt;br /&gt;
location = &amp;quot;nc_spm_08&amp;quot;&lt;br /&gt;
mapset   = &amp;quot;user1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
########### SOFTWARE&lt;br /&gt;
if sys.platform.startswith('linux'):&lt;br /&gt;
    # we assume that the GRASS GIS start script is available and in the PATH&lt;br /&gt;
    # query GRASS 7 itself for its GISBASE&lt;br /&gt;
    grass7bin = grass7bin_lin&lt;br /&gt;
elif sys.platform.startswith('win'):&lt;br /&gt;
    grass7bin = grass7bin_win&lt;br /&gt;
else:&lt;br /&gt;
    raise OSError('Platform not configured.')&lt;br /&gt;
&lt;br /&gt;
# query GRASS 7 itself for its GISBASE&lt;br /&gt;
startcmd = [grass7bin, '--config', 'path']&lt;br /&gt;
&lt;br /&gt;
p = subprocess.Popen(startcmd, shell=False,&lt;br /&gt;
                     stdout=subprocess.PIPE, stderr=subprocess.PIPE)&lt;br /&gt;
out, err = p.communicate()&lt;br /&gt;
if p.returncode != 0:&lt;br /&gt;
    print &amp;gt;&amp;gt;sys.stderr, &amp;quot;ERROR: Cannot find GRASS GIS 7 start script (%s)&amp;quot; % startcmd&lt;br /&gt;
    sys.exit(-1)&lt;br /&gt;
gisbase = out.strip('\n\r')&lt;br /&gt;
&lt;br /&gt;
# Set GISBASE environment variable&lt;br /&gt;
os.environ['GISBASE'] = gisbase&lt;br /&gt;
# the following not needed with trunk&lt;br /&gt;
os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'extrabin')&lt;br /&gt;
# add path to GRASS addons&lt;br /&gt;
home = os.path.expanduser(&amp;quot;~&amp;quot;)&lt;br /&gt;
os.environ['PATH'] += os.pathsep + os.path.join(home, '.grass7', 'addons', 'scripts')&lt;br /&gt;
&lt;br /&gt;
# define GRASS-Python environment&lt;br /&gt;
gpydir = os.path.join(gisbase, &amp;quot;etc&amp;quot;, &amp;quot;python&amp;quot;)&lt;br /&gt;
sys.path.append(gpydir)&lt;br /&gt;
&lt;br /&gt;
########### DATA&lt;br /&gt;
# Set GISDBASE environment variable&lt;br /&gt;
os.environ['GISDBASE'] = gisdb&lt;br /&gt;
 &lt;br /&gt;
# import GRASS Python bindings (see also pygrass)&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
import grass.script.setup as gsetup&lt;br /&gt;
 &lt;br /&gt;
###########&lt;br /&gt;
# launch session&lt;br /&gt;
gsetup.init(gisbase,&lt;br /&gt;
            gisdb, location, mapset)&lt;br /&gt;
 &lt;br /&gt;
gscript.message('Current GRASS GIS 7 environment:')&lt;br /&gt;
print gscript.gisenv()&lt;br /&gt;
 &lt;br /&gt;
gscript.message('Available raster maps:')&lt;br /&gt;
for rast in gscript.list_strings(type = 'rast'):&lt;br /&gt;
    print rast&lt;br /&gt;
 &lt;br /&gt;
gscript.message('Available vector maps:')&lt;br /&gt;
for vect in gscript.list_strings(type = 'vect'):&lt;br /&gt;
    print vect&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Python: GRASS GIS 7 without existing location using metadata only =====&lt;br /&gt;
&lt;br /&gt;
The script initializes the session, creates a temporary GRASS location and lists available raster and vector maps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# Python script to generate a new GRASS GIS 7 location simply from metadata&lt;br /&gt;
# Markus Neteler, 2014&lt;br /&gt;
&lt;br /&gt;
# ?? LINUX USAGE: First set LIBRARY SEARCH PATH&lt;br /&gt;
#export LD_LIBRARY_PATH=$(grass70 --config path)/lib&lt;br /&gt;
#python start_grass7_create_new_location_ADVANCED.py&lt;br /&gt;
&lt;br /&gt;
# some predefined variables&lt;br /&gt;
&lt;br /&gt;
# Windows&lt;br /&gt;
grass7path = r'C:\OSGeo4W\apps\grass\grass-7.0.svn'&lt;br /&gt;
grass7bin_win = r'C:\OSGeo4W\bin\grass70svn.bat'&lt;br /&gt;
# Linux&lt;br /&gt;
grass7bin_lin = 'grass70'&lt;br /&gt;
# MacOSX&lt;br /&gt;
grass7bin_mac = '/Applications/GRASS/GRASS-7.1.app/'&lt;br /&gt;
#myepsg = '4326' # latlong&lt;br /&gt;
myepsg = '3044' # ETRS-TM32, http://spatialreference.org/ref/epsg/3044/&lt;br /&gt;
#myfile = '/home/neteler/markus_repo/books/kluwerbook/data3rd/lidar/lidar_raleigh_nc_spm.shp'&lt;br /&gt;
myfile = '/data/maps/world_natural_earth_250m/europe_north_east.tif'&lt;br /&gt;
#myfile = r'C:\Dati\Padergnone\square_p95.tif'&lt;br /&gt;
&lt;br /&gt;
###########&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
import subprocess&lt;br /&gt;
import shutil&lt;br /&gt;
import binascii&lt;br /&gt;
import tempfile&lt;br /&gt;
&lt;br /&gt;
########### SOFTWARE&lt;br /&gt;
if sys.platform.startswith('linux'):&lt;br /&gt;
    # we assume that the GRASS GIS start script is available and in the PATH&lt;br /&gt;
    # query GRASS 7 itself for its GISBASE&lt;br /&gt;
    grass7bin = grass7bin_lin&lt;br /&gt;
elif sys.platform.startswith('win'):&lt;br /&gt;
    grass7bin = grass7bin_win&lt;br /&gt;
else:&lt;br /&gt;
    OSError('Platform not configured.')&lt;br /&gt;
&lt;br /&gt;
startcmd = grass7bin + ' --config path'&lt;br /&gt;
&lt;br /&gt;
p = subprocess.Popen(startcmd, shell=True, &lt;br /&gt;
					 stdout=subprocess.PIPE, stderr=subprocess.PIPE)&lt;br /&gt;
out, err = p.communicate()&lt;br /&gt;
if p.returncode != 0:&lt;br /&gt;
	print &amp;gt;&amp;gt;sys.stderr, 'ERROR: %s' % err&lt;br /&gt;
	print &amp;gt;&amp;gt;sys.stderr, &amp;quot;ERROR: Cannot find GRASS GIS 7 start script (%s)&amp;quot; % startcmd&lt;br /&gt;
	sys.exit(-1)&lt;br /&gt;
if sys.platform.startswith('linux'):&lt;br /&gt;
	gisbase = out.strip('\n')&lt;br /&gt;
elif sys.platform.startswith('win'):&lt;br /&gt;
    if out.find(&amp;quot;OSGEO4W home is&amp;quot;) != -1:&lt;br /&gt;
		gisbase = out.strip().split('\n')[1]&lt;br /&gt;
    else:&lt;br /&gt;
		gisbase = out.strip('\n')&lt;br /&gt;
    os.environ['GRASS_SH'] = os.path.join(gisbase, 'msys', 'bin', 'sh.exe')&lt;br /&gt;
&lt;br /&gt;
# Set GISBASE environment variable&lt;br /&gt;
os.environ['GISBASE'] = gisbase&lt;br /&gt;
# define GRASS-Python environment&lt;br /&gt;
gpydir = os.path.join(gisbase, &amp;quot;etc&amp;quot;, &amp;quot;python&amp;quot;)&lt;br /&gt;
sys.path.append(gpydir)&lt;br /&gt;
########&lt;br /&gt;
# define GRASS DATABASE&lt;br /&gt;
if sys.platform.startswith('win'):&lt;br /&gt;
    gisdb = os.path.join(os.getenv('APPDATA', 'grassdata')&lt;br /&gt;
else:&lt;br /&gt;
    gisdb = os.path.join(os.getenv('HOME', 'grassdata')&lt;br /&gt;
&lt;br /&gt;
# override for now with TEMP dir&lt;br /&gt;
gisdb = os.path.join(tempfile.gettempdir(), 'grassdata')&lt;br /&gt;
try:&lt;br /&gt;
    os.stat(gisdb)&lt;br /&gt;
except:&lt;br /&gt;
    os.mkdir(gisdb)&lt;br /&gt;
&lt;br /&gt;
# location/mapset: use random names for batch jobs&lt;br /&gt;
string_length = 16&lt;br /&gt;
location = binascii.hexlify(os.urandom(string_length))&lt;br /&gt;
mapset   = 'PERMANENT'&lt;br /&gt;
location_path = os.path.join(gisdb, location)&lt;br /&gt;
&lt;br /&gt;
# Create new location (we assume that grass7bin is in the PATH)&lt;br /&gt;
#  from EPSG code:&lt;br /&gt;
startcmd = grass7bin + ' -c epsg:' + myepsg + ' -e ' + location_path&lt;br /&gt;
#  from SHAPE or GeoTIFF file&lt;br /&gt;
#startcmd = grass7bin + ' -c ' + myfile + ' -e ' + location_path&lt;br /&gt;
&lt;br /&gt;
print startcmd&lt;br /&gt;
p = subprocess.Popen(startcmd, shell=True, &lt;br /&gt;
                     stdout=subprocess.PIPE, stderr=subprocess.PIPE)&lt;br /&gt;
out, err = p.communicate()&lt;br /&gt;
if p.returncode != 0:&lt;br /&gt;
    print &amp;gt;&amp;gt;sys.stderr, 'ERROR: %s' % err&lt;br /&gt;
    print &amp;gt;&amp;gt;sys.stderr, 'ERROR: Cannot generate location (%s)' % startcmd&lt;br /&gt;
    sys.exit(-1)&lt;br /&gt;
else:&lt;br /&gt;
    print 'Created location %s' % location_path&lt;br /&gt;
&lt;br /&gt;
# Now the location with PERMANENT mapset exists.&lt;br /&gt;
&lt;br /&gt;
########&lt;br /&gt;
# Now we can use PyGRASS or GRASS Scripting library etc. after &lt;br /&gt;
# having started the session with gsetup.init() etc&lt;br /&gt;
&lt;br /&gt;
# Set GISDBASE environment variable&lt;br /&gt;
os.environ['GISDBASE'] = gisdb&lt;br /&gt;
&lt;br /&gt;
# Linux: Set path to GRASS libs (TODO: NEEDED?)&lt;br /&gt;
path = os.getenv('LD_LIBRARY_PATH')&lt;br /&gt;
dir  = os.path.join(gisbase, 'lib')&lt;br /&gt;
if path:&lt;br /&gt;
    path = dir + os.pathsep + path&lt;br /&gt;
else:&lt;br /&gt;
    path = dir&lt;br /&gt;
os.environ['LD_LIBRARY_PATH'] = path&lt;br /&gt;
&lt;br /&gt;
# language&lt;br /&gt;
os.environ['LANG'] = 'en_US'&lt;br /&gt;
os.environ['LOCALE'] = 'C'&lt;br /&gt;
&lt;br /&gt;
# Windows: NEEDED?&lt;br /&gt;
#path = os.getenv('PYTHONPATH')&lt;br /&gt;
#dirr = os.path.join(gisbase, 'etc', 'python')&lt;br /&gt;
#if path:&lt;br /&gt;
#    path = dirr + os.pathsep + path&lt;br /&gt;
#else:&lt;br /&gt;
#    path = dirr&lt;br /&gt;
#os.environ['PYTHONPATH'] = path&lt;br /&gt;
&lt;br /&gt;
#print os.environ&lt;br /&gt;
&lt;br /&gt;
## Import GRASS Python bindings&lt;br /&gt;
import grass.script as grass&lt;br /&gt;
import grass.script.setup as gsetup&lt;br /&gt;
&lt;br /&gt;
###########&lt;br /&gt;
# Launch session and do something&lt;br /&gt;
gsetup.init(gisbase, gisdb, location, mapset)&lt;br /&gt;
&lt;br /&gt;
# say hello&lt;br /&gt;
grass.message('--- GRASS GIS 7: Current GRASS GIS 7 environment:')&lt;br /&gt;
print grass.gisenv()&lt;br /&gt;
&lt;br /&gt;
# do something in GRASS now...&lt;br /&gt;
&lt;br /&gt;
grass.message('--- GRASS GIS 7: Checking projection info:')&lt;br /&gt;
in_proj = grass.read_command('g.proj', flags = 'jf')&lt;br /&gt;
&lt;br /&gt;
# selective proj parameter printing&lt;br /&gt;
kv = grass.parse_key_val(in_proj)&lt;br /&gt;
print kv&lt;br /&gt;
print kv['+proj']&lt;br /&gt;
&lt;br /&gt;
# print full proj parameter printing&lt;br /&gt;
in_proj = in_proj.strip()&lt;br /&gt;
grass.message(&amp;quot;--- Found projection parameters: '%s'&amp;quot; % in_proj)&lt;br /&gt;
&lt;br /&gt;
# show current region:&lt;br /&gt;
grass.message('--- GRASS GIS 7: Checking computational region info:')&lt;br /&gt;
in_region = grass.region()&lt;br /&gt;
grass.message(&amp;quot;--- Computational region: '%s'&amp;quot; % in_region)&lt;br /&gt;
&lt;br /&gt;
# do something else: r.mapcalc, v.rectify, ...&lt;br /&gt;
&lt;br /&gt;
# Finally remove the temporary batch location from disk&lt;br /&gt;
print 'Removing location %s' % location_path&lt;br /&gt;
shutil.rmtree(location_path)&lt;br /&gt;
&lt;br /&gt;
sys.exit(0)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Python: GRASS GIS 6 =====&lt;br /&gt;
&lt;br /&gt;
The script initializes the session and lists available raster maps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
gisbase = os.environ['GISBASE'] = &amp;quot;/usr/local/src/grass_trunk/dist.x86_64-unknown-linux-gnu&amp;quot;&lt;br /&gt;
&lt;br /&gt;
gisdbase = os.path.join(os.environ['HOME'], &amp;quot;grassdata&amp;quot;)&lt;br /&gt;
location = &amp;quot;nc_spm_08&amp;quot;&lt;br /&gt;
mapset   = &amp;quot;user1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
sys.path.append(os.path.join(os.environ['GISBASE'], &amp;quot;etc&amp;quot;, &amp;quot;python&amp;quot;))&lt;br /&gt;
import grass.script as grass&lt;br /&gt;
import grass.script.setup as gsetup&lt;br /&gt;
&lt;br /&gt;
gsetup.init(gisbase,&lt;br /&gt;
            gisdbase, location, mapset)&lt;br /&gt;
&lt;br /&gt;
print grass.gisenv()&lt;br /&gt;
&lt;br /&gt;
grass.message('Raster maps:')&lt;br /&gt;
for rast in grass.list_strings(type = 'rast'):&lt;br /&gt;
    print rast&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Bash examples (GNU/Linux) ====&lt;br /&gt;
&lt;br /&gt;
Below an example of a '''~/.bash_profile''' script to set the required settings in order to access GRASS commands outside of a GRASS-session. Specifically it is for GRASS 7 (commented parts for GRASS 6.4.2):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
# example for GRASS 7&lt;br /&gt;
export GISBASE=/usr/local/grass-7.0.svn&lt;br /&gt;
# example for GRASS 6.4.2&lt;br /&gt;
### export GISBASE=/usr/local/grass-6.4.2svn&lt;br /&gt;
&lt;br /&gt;
# GRASS 7&lt;br /&gt;
export GRASS_VERSION=&amp;quot;7.0.svn&amp;quot;&lt;br /&gt;
# GRASS 6.4.2&lt;br /&gt;
### export GRASS_VERSION=&amp;quot;6.4.2svn&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#generate GISRCRC&lt;br /&gt;
MYGISDBASE=$HOME/grassdata&lt;br /&gt;
MYLOC=nc_spm_08&lt;br /&gt;
MYMAPSET=user1&lt;br /&gt;
&lt;br /&gt;
# Set the global grassrc file to individual file name&lt;br /&gt;
MYGISRC=&amp;quot;$HOME/.grassrc.$GRASS_VERSION.$$&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;GISDBASE: $MYGISDBASE&amp;quot; &amp;gt; &amp;quot;$MYGISRC&amp;quot;&lt;br /&gt;
echo &amp;quot;LOCATION_NAME: $MYLOC&amp;quot; &amp;gt;&amp;gt; &amp;quot;$MYGISRC&amp;quot;&lt;br /&gt;
echo &amp;quot;MAPSET: $MYMAPSET&amp;quot; &amp;gt;&amp;gt; &amp;quot;$MYGISRC&amp;quot;&lt;br /&gt;
echo &amp;quot;GRASS_GUI: text&amp;quot; &amp;gt;&amp;gt; &amp;quot;$MYGISRC&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
# path to GRASS settings file&lt;br /&gt;
export GISRC=$MYGISRC&lt;br /&gt;
export GRASS_PYTHON=python&lt;br /&gt;
export GRASS_MESSAGE_FORMAT=plain&lt;br /&gt;
export GRASS_TRUECOLOR=TRUE&lt;br /&gt;
export GRASS_TRANSPARENT=TRUE&lt;br /&gt;
export GRASS_PNG_AUTO_WRITE=TRUE&lt;br /&gt;
export GRASS_GNUPLOT='gnuplot -persist'&lt;br /&gt;
export GRASS_WIDTH=640&lt;br /&gt;
export GRASS_HEIGHT=480&lt;br /&gt;
export GRASS_HTML_BROWSER=firefox&lt;br /&gt;
export GRASS_PAGER=cat&lt;br /&gt;
export GRASS_WISH=wish&lt;br /&gt;
        &lt;br /&gt;
export PATH=&amp;quot;$GISBASE/bin:$GISBASE/scripts:$PATH&amp;quot;&lt;br /&gt;
export LD_LIBRARY_PATH=&amp;quot;$GISBASE/lib&amp;quot;&lt;br /&gt;
export GRASS_LD_LIBRARY_PATH=&amp;quot;$LD_LIBRARY_PATH&amp;quot;&lt;br /&gt;
export PYTHONPATH=&amp;quot;$GISBASE/etc/python:$PYTHONPATH&amp;quot;&lt;br /&gt;
export MANPATH=$MANPATH:$GISBASE/man&lt;br /&gt;
&lt;br /&gt;
#For the temporal modules&lt;br /&gt;
export TGISDB_DRIVER=sqlite&lt;br /&gt;
export TGISDB_DATABASE=$MYGISDBASE/$MYLOC/PERMANENT/tgis/sqlite.db&lt;br /&gt;
&lt;br /&gt;
# test a command&lt;br /&gt;
g.list rast&lt;br /&gt;
&lt;br /&gt;
######### below not needed ########&lt;br /&gt;
# GRASS 7&lt;br /&gt;
tmp=/tmp/grass7-&amp;quot;`whoami`&amp;quot;-$GIS_LOCK&lt;br /&gt;
# GRASS 6.4.2&lt;br /&gt;
### tmp=/tmp/grass6-&amp;quot;`whoami`&amp;quot;-$GIS_LOCK&lt;br /&gt;
&lt;br /&gt;
export GISRC=&amp;quot;$tmp/rc&amp;quot;&lt;br /&gt;
mkdir &amp;quot;$tmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# GRASS 7&lt;br /&gt;
cp ~/.grass7/rc &amp;quot;$GISRC&amp;quot;&lt;br /&gt;
# GRASS 6.4.2&lt;br /&gt;
### cp ~/.grassrc6 &amp;quot;$GISRC&amp;quot;&lt;br /&gt;
######### END below not needed ########&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above script will allow GRASS commands to be used anywhere. Furthermore, if the '''~/.Xsession''' sources the bash startup scripts, the settings aren't limited to interactive shells, but also work for e.g. M-! in XEmacs). Each interactive shell gets a separate &amp;quot;session&amp;quot; (i.e. a separate $GISRC file), while GUI programs share a common session.&lt;br /&gt;
&lt;br /&gt;
Note, however, that '''~/.bash_profile''' is a personal initialization startup script and, thus, read during the login process. Any modifications to it will be read after (re-)login or explicitly sourcing it.&lt;br /&gt;
&lt;br /&gt;
At the end of the ~/.bash_profile file, the following lines can be added to ensure no duplication of entries in the PATH variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=bash&amp;gt;&lt;br /&gt;
 PATH=`awk -F: '{for(i=1;i&amp;lt;=NF;i++){if(!($i in a)){a[$i];printf s$i;s=&amp;quot;:&amp;quot;}}}'&amp;lt;&amp;lt;&amp;lt;$PATH`&lt;br /&gt;
 PYTHONPATH=`awk -F: '{for(i=1;i&amp;lt;=NF;i++){if(!($i in a)){a[$i];printf s$i;s=&amp;quot;:&amp;quot;}}}'&amp;lt;&amp;lt;&amp;lt;$PYTHONPATH`&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Important notes ===&lt;br /&gt;
&lt;br /&gt;
Launching a grassXY session could still permit access on GRASS modules of the version that is set with the above script. The reason being is that grassXY scripts (e.g.: grass64, grass65, grass70) prepend the GRASS directories to '''PATH''', '''LD_LIBRARY_PATH''', etc. They won't remove any entries which are already there. A solution to this is to ''switch'' between GRASS versions by using a script like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
        strippath()&lt;br /&gt;
        {&lt;br /&gt;
            (&lt;br /&gt;
            oldpath=&amp;quot;$1&amp;quot;&lt;br /&gt;
            newpath=&lt;br /&gt;
            IFS=:&lt;br /&gt;
            for dir in $oldpath ; do&lt;br /&gt;
                case &amp;quot;${dir}&amp;quot; in&lt;br /&gt;
                *grass*)&lt;br /&gt;
                        ;;&lt;br /&gt;
                *)&lt;br /&gt;
                        newpath=&amp;quot;$newpath:$dir&amp;quot;&lt;br /&gt;
                        ;;&lt;br /&gt;
                esac&lt;br /&gt;
            done&lt;br /&gt;
            echo &amp;quot;${newpath#:}&amp;quot;&lt;br /&gt;
            )&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        PATH=`strippath $PATH`&lt;br /&gt;
        &lt;br /&gt;
        export GISBASE=$PWD/dist.i686-pc-linux-gnu&lt;br /&gt;
        export PATH=&amp;quot;$GISBASE/bin:$GISBASE/scripts:$PATH&amp;quot;&lt;br /&gt;
        export LD_LIBRARY_PATH=&amp;quot;$GISBASE/lib&amp;quot;&lt;br /&gt;
        export PYTHONPATH=&amp;quot;$GISBASE/etc/python&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note: the above script needs to be &amp;quot;source&amp;quot;d; executing it won't work. It might also require some adjustments (e.g. the ''GISBASE'' variable).'''&lt;br /&gt;
&lt;br /&gt;
Using normal grass sessions commands are recorded in '''$GISDBASE/$LOCATION_NAME/$MAPSET/.bash_history'''. While working with &amp;quot;pure&amp;quot; bash, shell entries go in '''~/.bash_history'''. Merging existing &amp;quot;grass-bash_history(-ies)&amp;quot; with the bash history log, would probably be not a good idea. Perhaps it is wise(r) to use normal GRASS sessions when working on real projects. Nevertheless, it is upon the users preferences and expertise level to decide what is best.&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
* Instructions and discussion on ''how to access GRASS mapsets outside of a GRASS session'' in the grass-user mailing list [http://n2.nabble.com/can-I-access-mapset-outside-of-grass-by-using-python-td3405902.html#a3405902].&lt;br /&gt;
* removing duplicate entries in $PATH taken from [http://chunchung.blogspot.com/2007/11/remove-duplicate-paths-from-path-in.html]&lt;br /&gt;
&lt;br /&gt;
== GRASS databases ==&lt;br /&gt;
&lt;br /&gt;
(project file structure)&lt;br /&gt;
&lt;br /&gt;
=== Minimal mapsets ===&lt;br /&gt;
&lt;br /&gt;
within a functional LOCATION (see below) the minimal mapset is a subdirectory of the MAPSET's name, containing a WIND file. The WIND file can simply be copied from PERMANENT/DEFAULT_WIND. Optionally you can put a VAR file in there too to define the default database driver to use.&lt;br /&gt;
&lt;br /&gt;
* You can create a new mapset when starting GRASS with the -c flag. e.g.&lt;br /&gt;
 grass64 -c /path/to/location/new_mapset_name&lt;br /&gt;
&lt;br /&gt;
=== Minimal locations ===&lt;br /&gt;
&lt;br /&gt;
Within the GISDATABASE (which is simply a subdirectory some where), the minimum LOCATION consists of a directory giving the LOCATION its name, which in turn contains a PERMANENT subdirectory for the PERMANENT mapset. The PERMANENT mapset contains a few special files that regular mapsets don't. These are:&lt;br /&gt;
; PROJ_INFO: contains the location's projection information&lt;br /&gt;
; PROJ_UNITS: contains the location's map units definition&lt;br /&gt;
; DEFAULT_WIND: the default region (WINDow file). The format is identical to the WIND files created by g.region&lt;br /&gt;
; WIND: (optional?)&lt;br /&gt;
&lt;br /&gt;
* see also {{src|demolocation}} in the GRASS source code&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[GRASS_and_Shell#GRASS_Batch_jobs|GRASS Batch jobs]]&lt;br /&gt;
&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
[[Category: Linking to other languages]]&lt;br /&gt;
[[Category: bash]]&lt;br /&gt;
[[Category:Scripting]]&lt;br /&gt;
[[Category: Python]]&lt;/div&gt;</summary>
		<author><name>⚠️Osfraid</name></author>
	</entry>
</feed>