-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetJSONObjectPropertyValue
More file actions
executable file
·47 lines (44 loc) · 1.39 KB
/
getJSONObjectPropertyValue
File metadata and controls
executable file
·47 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /bin/bash -
# 用于读取JSON格式配置文件,并返回可读值。
LC_ALL=C
PRG="$0"
PRGDIR=`dirname "${PRG}"`"/"
object="{}"
propertyName="property"
## STARTRegion LongOption
# from /usr/share/doc/util-linux/examples/getopt-parse.bash
# Note that we use `"$@"' to let each command-line parameter expand to a
# separate word. The quotes around `$@' are essential!
# We need TEMP as the `eval set --' would nuke the return value of getopt.
TEMP=`getopt -o o:p: --long object:,propertyName: \
-n 'example.bash' -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
while true ; do
case "$1" in
-o|--object) object=$2 ; shift 2 ;;
-p|--propertyName) propertyName=$2 ; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
done
if [ 0 -ne ${#1} ];
then
echo "Remaining arguments:";
for arg do echo '--> '"\`$arg'" ; done
fi
## ENDRegion LongOption
## BEGIN pre-format parameters
object=${object}
propertyName=${propertyName}
## END pre-format parameters
## BEGIN deal the status of config file's existence.
function getPropertyValueFromObject(){
echo ${object} | python -c 'import json,sys;obj=json.load(sys.stdin);print json.dumps(obj'${propertyName}')';
}
## END deal the status of config file's existence.
## BEGIN to execute
getPropertyValueFromObject
#echo "Done."
## END of execute