improve error exit from script (kill self).
protect functions vs. wrong use (check param 3 of addpath; deny param 3 for append and prepend).
quote several expressions (to allow installation paths containing spaces)
http://bugs.arb-home.de/changeset/18439
--- SH/arb	(revision 18438)
+++ SH/arb	(revision 18439)
@@ -3,8 +3,10 @@
 # set -x
 
-# error message function
-err () {
-	echo "`basename $0`: $@" 1>&2
-	exit 1
+# error message function (nested exit):
+trap "exit 1" TERM
+export ARB_SCRIPT_PID=$$
+abort_script_with() {
+    echo "`basename $0`: $@" 1>&2
+    kill -s TERM $ARB_SCRIPT_PID
 }
 
@@ -16,5 +18,5 @@
     me="${BASH_SOURCE[0]}"
     # while me is symlink
-    while [ -h "$me" ]; do 
+    while [ -h "$me" ]; do
         # change to directory where symlink "$me" resides
         cd "$(dirname "$me")"
@@ -37,5 +39,5 @@
     eval value=\"\$\{$1:-\}\"
     case "$value" in
-	*:$2:*|*:$2|$2:*|$2)
+	*:${2}:*|*:${2}|${2}:*|${2})
 	    result="$value"
 	    ;;
@@ -45,13 +47,16 @@
 	*)
 	    case "$3" in
-		p*)
+		prepend)
 		    result="$2:${value}"
 		    ;;
+		append)
+		    result="${value}:$2"
+		    ;;
 		*)
-		    result="${value}:$2"
+		    abort_script_with "addpath expects param 'append' or 'prepend'"
 		    ;;
 	    esac
     esac
-    eval $1=$result
+    eval "$1=\"$result\""
     unset result value
 }
@@ -59,4 +64,7 @@
 # convenience routine which appends a string to a path.
 append () {
+    if [ -n "${3:-}" ]; then
+	    abort_script_with too many arguments to append: "\$3=$3"
+    fi
     addpath "$1" "$2" append
 }
@@ -64,4 +72,7 @@
 # convenience routine which prepends a string to a path.
 prepend () {
+    if [ -n "${3:-}" ]; then
+	    abort_script_with too many arguments to prepend: "\$3=$3"
+    fi
     addpath "$1" "$2" prepend
 }
@@ -90,20 +101,20 @@
 
 # use ARBHOME defined by location of script (comment out for old behavior)
-ARBHOME=$ARBHOME_OF_SCRIPT
+ARBHOME="$ARBHOME_OF_SCRIPT"
 
 echo "Using ARBHOME='$ARBHOME'"
 
-prepend PATH			$ARBHOME/bin
-prepend LD_LIBRARY_PATH		$ARBHOME/lib
+prepend PATH			"$ARBHOME/bin"
+prepend LD_LIBRARY_PATH		"$ARBHOME/lib"
 append  LD_LIBRARY_PATH		/usr/dt/lib
 append  LD_LIBRARY_PATH		/usr/openwin/lib
-append  LD_LIBRARY_PATH		$ARBHOME/lib/addlibs
-prepend SHLIB_PATH		$ARBHOME/lib
-append  SHLIB_PATH		$ARBHOME/lib/addlibs
-append  PYTHONPATH      $ARBHOME/lib/python2.6
-append  PERl5LIB        $ARBHOME/lib/perl5  
+append  LD_LIBRARY_PATH		"$ARBHOME/lib/addlibs"
+prepend SHLIB_PATH		"$ARBHOME/lib"
+append  SHLIB_PATH		"$ARBHOME/lib/addlibs"
+append  PYTHONPATH      	"$ARBHOME/lib/python2.6"
+append  PERl5LIB        	"$ARBHOME/lib/perl5"
 
 # environment variables that this shell script sets/changes:
-export LD_LIBRARY_PATH MANPATH PATH ARBHOME SHLIB_PATH 
+export LD_LIBRARY_PATH MANPATH PATH ARBHOME SHLIB_PATH
 export PYTHONPATH PERL5LIB
 
@@ -112,5 +123,5 @@
 export PWD HOME USER
 
-if [ -x $ARBHOME/bin/ghostview ] ; then
+if [ -x "$ARBHOME/bin/ghostview" ] ; then
   GS_LIB="$ARBHOME/DEPOT/ghostscript"
   export GS_LIB
@@ -120,17 +131,17 @@
 
 if [ -z ${ARB_PROP:-} ]; then
-    ARB_PROP=${HOME}/.arb_prop
+    ARB_PROP="${HOME}/.arb_prop"
 fi
 echo "Using properties from $ARB_PROP"
-if [ ! -d ${ARB_PROP} ] ; then
+if [ ! -d "${ARB_PROP}" ] ; then
   echo "Directory ${ARB_PROP} not found - creating ..."
-  mkdir ${ARB_PROP}
+  mkdir "${ARB_PROP}"
 fi
 export ARB_PROP
 
-ARB_LOCAL_PTS=${HOME}/.arb_pts
-if [ ! -d ${ARB_LOCAL_PTS} ] ; then
+ARB_LOCAL_PTS="${HOME}/.arb_pts"
+if [ ! -d "${ARB_LOCAL_PTS}" ] ; then
   echo "Directory ${ARB_LOCAL_PTS} not found - creating ..."
-  mkdir ${ARB_LOCAL_PTS}
+  mkdir "${ARB_LOCAL_PTS}"
 fi
 
@@ -138,16 +149,16 @@
   ARBMACROHOME="${ARB_PROP}/macros";
 fi
-if [ ! -d ${ARBMACROHOME} ] ; then
+if [ ! -d "${ARBMACROHOME}" ] ; then
   echo "Directory $ARBMACROHOME not found - creating ..."
-  mkdir ${ARBMACROHOME}
+  mkdir "${ARBMACROHOME}"
 fi
 export ARBMACROHOME
 
-if [ -z ${ARBMACRO:-} ] ; then
+if [ -z "${ARBMACRO:-}" ] ; then
   ARBMACRO="$ARBHOME/lib/macros"
 fi
-if [ ! -d ${ARBMACRO} ] ; then
+if [ ! -d "${ARBMACRO}" ] ; then
   echo "Directory $ARBMACRO not found - creating ..."
-  mkdir ${ARBMACRO}
+  mkdir "${ARBMACRO}"
 fi
 export ARBMACRO
