fixes #1
This commit is contained in:
parent
ff53007b62
commit
ecf151ea40
32
tomcat
32
tomcat
@ -2,36 +2,44 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
ARG="$(printf "%s\n" "$1" | sed -n '/-/p')"
|
||||||
|
|
||||||
# check usage
|
# check usage
|
||||||
if ! test -n "$1"; then
|
if ! test -n "$1"; then
|
||||||
printf "Usage: %s [TABLE.KEY[INDEX]] [FILE]\n" "$0" 1>&2
|
printf "Usage: %s [OPTIONS] [TABLE.KEY[INDEX]] [FILE]\n" "$0" 1>&2
|
||||||
exit 64 # sysexits(3) EX_USAGE
|
exit 64 # sysexits(3) EX_USAGE
|
||||||
|
elif test -n "$ARG"; then
|
||||||
|
argv1="$2"
|
||||||
|
argv2="$3"
|
||||||
|
else
|
||||||
|
argv1="$1"
|
||||||
|
argv2="$2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# test if input has a period
|
# test if input has a period
|
||||||
if test -n $(printf "%s\n" "$1" | sed -n '/.*\..*/p'); then
|
if test -n "$(printf "%s\n" "$argv1" | sed -n '/.*\..*/p')"; then
|
||||||
# cut out everything beyond the first period for TABLE
|
# cut out everything beyond the first period for TABLE
|
||||||
TABLE=$(printf "%s\n" "$1" | sed -n 's/\..*//p')
|
TABLE=$(printf "%s\n" "$argv1" | sed -n 's/\..*//p')
|
||||||
|
|
||||||
# cut out everything before the first period for KEY
|
# cut out everything before the first period for KEY
|
||||||
KEY=$(printf "%s\n" "$1" | sed -n 's/^[^.]\+\.//p')
|
KEY=$(printf "%s\n" "$argv1" | sed -n 's/^[^.]\+\.//p')
|
||||||
else
|
else
|
||||||
# set key to input if there is no table specified
|
# set key to input if there is no table specified
|
||||||
KEY=$1
|
KEY=$argv1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove array index from KEY
|
# remove array index from KEY
|
||||||
KEY=$(printf "%s\n" "$KEY" | sed 's/\[.*\]//g')
|
KEY=$(printf "%s\n" "$KEY" | sed 's/\[.*\]//g')
|
||||||
# set ARR to the array index
|
# set ARR to the array index
|
||||||
ARR=$(printf "%s\n" "$1" | sed -n 's/.\+\[//p' | tr -d ']')
|
ARR=$(printf "%s\n" "$argv1" | sed -n 's/.\+\[//p' | tr -d ']')
|
||||||
|
|
||||||
# test if argument 2 is a file or not
|
# test if argument 2 is a file or not
|
||||||
if test -e "$2"; then
|
if test -e "$argv2"; then
|
||||||
# set TOML to the text from the file
|
# set TOML to the text from the file
|
||||||
TOML=$(sed 's/[^"#]#\+.*//g' <"$2" | sed 's/^#.*//g' )
|
TOML=$(sed 's/[^"#]#\+.*//g' <"$argv2" | sed 's/^#.*//g' )
|
||||||
else
|
else
|
||||||
# set TOML to the text from stdin
|
# set TOML to the text from stdin
|
||||||
TOML=$(printf "%s\n" "$2" | sed 's/[^"#]#\+.*//g')
|
TOML=$(printf "%s\n" "$argv2" | sed 's/[^"#]#\+.*//g')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set VAL to the parsed TOML
|
# set VAL to the parsed TOML
|
||||||
@ -49,7 +57,11 @@ if test -n "$ARR"; then
|
|||||||
printf "%s\n" "$VAL" | sed 's/ /\n/g' | head -n "$ARR" |\
|
printf "%s\n" "$VAL" | sed 's/ /\n/g' | head -n "$ARR" |\
|
||||||
tail -n 1
|
tail -n 1
|
||||||
else
|
else
|
||||||
# remove quotes and output VAL
|
if test -n "$ARG"; then
|
||||||
|
if [ "$1" = "-c" ] || [ "$1" = "--count" ]; then
|
||||||
|
VAL="$(printf "%s\n" "$VAL" | sed 's/ /\n/g' | wc -l)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
printf "%s\n" "$VAL"
|
printf "%s\n" "$VAL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user