lib/Tools/getenv
author wenzelm
Fri Sep 01 17:50:36 2000 +0200 (2000-09-01)
changeset 9788 df671fa2562a
parent 3007 e5efa177ee0c
child 10511 efb3428c9879
permissions -rwxr-xr-x
GPLed;
more robust handling of spaces in args / file names;
     1 #!/bin/bash
     2 #
     3 # $Id$
     4 # Author: Markus Wenzel, TU Muenchen
     5 # License: GPL (GNU GENERAL PUBLIC LICENSE)
     6 #
     7 # DESCRIPTION: get values from Isabelle settings environment
     8 
     9 
    10 ## diagnostics
    11 
    12 PRG=$(basename "$0")
    13 
    14 function usage()
    15 {
    16   echo
    17   echo "Usage: $PRG [OPTIONS] [VARNAMES ...]"
    18   echo
    19   echo "  Options are:"
    20   echo "    -a           display complete environment"
    21   echo "    -b           print values only (doesn't work for -a)"
    22   echo
    23   echo "  Get value of VARNAMES from the Isabelle settings."
    24   echo
    25   exit 1
    26 }
    27 
    28 
    29 ## process command line
    30 
    31 # options
    32 
    33 ALL=""
    34 BASE=""
    35 
    36 while getopts "ab" OPT
    37 do
    38   case "$OPT" in
    39     a)
    40       ALL=true
    41       ;;
    42     b)
    43       BASE=true
    44       ;;
    45     \?)
    46       usage
    47       ;;
    48   esac
    49 done
    50 
    51 shift $(($OPTIND - 1))
    52 
    53 
    54 # args
    55 
    56 [ -n "$ALL" -a "$#" -ne 0 ] && usage
    57 
    58 
    59 ## main
    60 
    61 if [ -n "$ALL" ]; then
    62   env | sort
    63 else
    64   for VAR in "$@"
    65   do
    66     if [ -n "$BASE" ]; then
    67       eval "echo \$$VAR"
    68     else
    69       eval "echo $VAR=\$$VAR"
    70     fi
    71   done
    72 fi