Script portability

From GRASS-Wiki
Revision as of 12:22, 4 May 2012 by ⚠️Afrigeri (talk | contribs) (Created page with "=== Make GRASS shell scripts portable === :::::: Portable shell scripting is something of a black art, since with the evolution and derivation of the UNIX shell, the definiti...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Make GRASS shell scripts portable

Portable shell scripting is something of a black art, since with the evolution and derivation of the UNIX shell, the definition of "portable" is perhaps ambiguous.
_Simon__Nattrass_

Guidelines

Conditionals

Conditional with [ ... ] should replaced by __test__

               	         
if [ -f foo.c ] 
then
...
fi

as here:

 
if test -f foo.c
then
...
fi

Arithmetics

Expression with $(( ... ))

 
x=$(($x+1))

are more portable if using __expr__

              
x=`expr $x + 1`

References