arrays!!!!!

This commit is contained in:
Emma Tebibyte 2022-11-06 21:55:49 -05:00
parent 36fd58b392
commit d9b397cd47

23
tomcat
View File

@ -2,8 +2,11 @@
set -e
argv1=$1
argv2=$2
# check usage
if ! test -n "$1"; then
if ! test -n "$argv1"; then
printf "Usage: %s [resource...]\n" "$0" 1>&2
exit 64 # sysexits(3) EX_USAGE
fi
@ -13,21 +16,19 @@ if ! test -e "$1"; then
exit 66 # sysexits(3) EX_NOINPUT
fi
TOML=$(sed 's/[^"#]#\+.*//g' <"$1")
set -- $(printf "%s\n" "$argv2" | cut -d "." --output-delimiter=" " -f 1-)
PAIRS=$(printf "%s\n" "$(sed 's/[^"#]#\+.*//g' <"$argv1")" | awk "/^\[$1\]/{flag=1; next} /^\[/{flag=0} flag" - )
set -- $(printf "%s\n" "$2" | cut -d "." --output-delimiter=" " -f 1-)
PAIRS=$(printf "%s\n" "$TOML" | awk "/^\[$1\]/{flag=1; next} /^\[/{flag=0} flag" - )
ARR=$(printf "%s\n" "$2" | sed -n 's/.\+\[//p' | tr -d ']')
ARR=$(printf "%s\n" "$2" | sed -n 's/.\+\[//p')
ARG=$(printf "%s\n" "$2" | sed 's/\[.*\]//g')
VAL=$(printf "%s\n" "$PAIRS" | sed -n "s/$2 *= *//p" | sed 's/, /,/g' | tr -d '[]')
VAL=$(printf "%s\n" "$PAIRS" | sed -n "s/$ARG *= *//p" | sed 's/", "/","/g' | tr -d '[]' | sed 's/^ //g')
if test -n "$ARR"; then
set -- $(printf "%s\n" "$VAL" | cut -d "," --output-delimiter=" " -f 1-)
POS=$(printf "%s\n" "$ARR" |tr -d ']')
else
printf "%s\n" "$VAL"
VAL=$(printf "%s\n" "$VAL" | sed -n 's/,/\n/p' | tr -d '"' | head -n "$ARR" | tail -n 1)
fi
printf "%s\n" "$VAL"
exit 0