lib/Tools/getenv
author wenzelm
Wed, 31 Mar 2021 11:24:46 +0200
changeset 73772 d3f2038198ae
parent 62828 3fee575c9dce
child 73837 cd84e58aed26
permissions -rwxr-xr-x
clarified (again): local tip could be actually more recent;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10555
2323ec838401 /usr/bin/env bash;
wenzelm
parents: 10511
diff changeset
     1
#!/usr/bin/env bash
2296
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
     2
#
9788
wenzelm
parents: 3007
diff changeset
     3
# Author: Markus Wenzel, TU Muenchen
2307
508d2a233dbc *** empty log message ***
wenzelm
parents: 2296
diff changeset
     4
#
2734
e9bbef1b2fbe improved DESCRIPTION;
wenzelm
parents: 2733
diff changeset
     5
# DESCRIPTION: get values from Isabelle settings environment
2307
508d2a233dbc *** empty log message ***
wenzelm
parents: 2296
diff changeset
     6
2296
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
     7
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
     8
## diagnostics
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
     9
10511
wenzelm
parents: 9788
diff changeset
    10
PRG="$(basename "$0")"
2296
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    11
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    12
function usage()
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    13
{
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    14
  echo
28650
a7ba12e0d3b7 tuned usage line;
wenzelm
parents: 17226
diff changeset
    15
  echo "Usage: isabelle $PRG [OPTIONS] [VARNAMES ...]"
2296
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    16
  echo
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    17
  echo "  Options are:"
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    18
  echo "    -a           display complete environment"
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    19
  echo "    -b           print values only (doesn't work for -a)"
31497
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    20
  echo "    -d FILE      dump complete environment to FILE"
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    21
  echo "                 (null terminated entries)"
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    22
  echo
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    23
  echo "  Get value of VARNAMES from the Isabelle settings."
2296
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    24
  echo
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    25
  exit 1
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    26
}
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    27
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    28
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    29
## process command line
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    30
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    31
# options
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    32
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    33
ALL=""
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    34
BASE=""
31497
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    35
DUMP=""
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    36
31497
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    37
while getopts "abd:" OPT
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    38
do
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    39
  case "$OPT" in
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    40
    a)
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    41
      ALL=true
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    42
      ;;
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    43
    b)
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    44
      BASE=true
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    45
      ;;
31497
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    46
    d)
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    47
      DUMP="$OPTARG"
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    48
      ;;
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    49
    \?)
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    50
      usage
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    51
      ;;
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    52
  esac
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    53
done
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    54
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    55
shift $(($OPTIND - 1))
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    56
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    57
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    58
# args
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    59
62828
3fee575c9dce clarified usage;
wenzelm
parents: 61294
diff changeset
    60
[ -z "$ALL" -a -z "$DUMP" -a "$#" -eq 0 ] && usage
9788
wenzelm
parents: 3007
diff changeset
    61
[ -n "$ALL" -a "$#" -ne 0 ] && usage
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    62
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    63
2296
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    64
## main
3b1086cf2f4d getenv: get value from Isabelle settings.
wenzelm
parents:
diff changeset
    65
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    66
if [ -n "$ALL" ]; then
17226
0687c76021c0 refrain from sorting output;
wenzelm
parents: 14981
diff changeset
    67
  env
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    68
else
9788
wenzelm
parents: 3007
diff changeset
    69
  for VAR in "$@"
2733
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    70
  do
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    71
    if [ -n "$BASE" ]; then
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    72
      eval "echo \$$VAR"
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    73
    else
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    74
      eval "echo $VAR=\$$VAR"
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    75
    fi
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    76
  done
1d1013313201 added -a, -b options;
wenzelm
parents: 2335
diff changeset
    77
fi
31497
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    78
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    79
if [ -n "$DUMP" ]; then
61294
2d3d26e9b191 renamed jvmpath to platform_path;
wenzelm
parents: 47674
diff changeset
    80
  export PATH_JVM="$(platform_path "$PATH")"
31497
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    81
  exec perl -w -e 'for $key (keys %ENV) { print $key, "=", $ENV{$key}, "\x00"; }' > "$DUMP"
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    82
fi
5333aa739082 isabelle getenv: option -d;
wenzelm
parents: 29143
diff changeset
    83