lib/Tools/getenv
author wenzelm
Sun Apr 03 19:47:29 2016 +0200 (2016-04-03)
changeset 62828 3fee575c9dce
parent 61294 2d3d26e9b191
permissions -rwxr-xr-x
clarified usage;
     1 #!/usr/bin/env bash
     2 #
     3 # Author: Markus Wenzel, TU Muenchen
     4 #
     5 # DESCRIPTION: get values from Isabelle settings environment
     6 
     7 
     8 ## diagnostics
     9 
    10 PRG="$(basename "$0")"
    11 
    12 function usage()
    13 {
    14   echo
    15   echo "Usage: isabelle $PRG [OPTIONS] [VARNAMES ...]"
    16   echo
    17   echo "  Options are:"
    18   echo "    -a           display complete environment"
    19   echo "    -b           print values only (doesn't work for -a)"
    20   echo "    -d FILE      dump complete environment to FILE"
    21   echo "                 (null terminated entries)"
    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 DUMP=""
    36 
    37 while getopts "abd:" OPT
    38 do
    39   case "$OPT" in
    40     a)
    41       ALL=true
    42       ;;
    43     b)
    44       BASE=true
    45       ;;
    46     d)
    47       DUMP="$OPTARG"
    48       ;;
    49     \?)
    50       usage
    51       ;;
    52   esac
    53 done
    54 
    55 shift $(($OPTIND - 1))
    56 
    57 
    58 # args
    59 
    60 [ -z "$ALL" -a -z "$DUMP" -a "$#" -eq 0 ] && usage
    61 [ -n "$ALL" -a "$#" -ne 0 ] && usage
    62 
    63 
    64 ## main
    65 
    66 if [ -n "$ALL" ]; then
    67   env
    68 else
    69   for VAR in "$@"
    70   do
    71     if [ -n "$BASE" ]; then
    72       eval "echo \$$VAR"
    73     else
    74       eval "echo $VAR=\$$VAR"
    75     fi
    76   done
    77 fi
    78 
    79 if [ -n "$DUMP" ]; then
    80   export PATH_JVM="$(platform_path "$PATH")"
    81   exec perl -w -e 'for $key (keys %ENV) { print $key, "=", $ENV{$key}, "\x00"; }' > "$DUMP"
    82 fi
    83