Im trying to parse an xml file and get all tag values and fonts values and add them to an associative arrays. My issue is that the array doesn't seem to be having the values assigned to it properly
#!/bin/bash
GAME_NAME="."
LOCALIZATION_DIR="$GAME_NAME/assets/data/localization"
INDEX=0
OUTPUT_KEYS=()
# parse english xml for tags and font names first
for str in $(echo "cat //strings/string/@key" | xmllint --shell "$LOCALIZATION_DIR/en.xml")
do
echo "$str"
echo "--"
OUTPUT_KEYS[$index]="$str"
((INDEX++))
done
echo ${OUTPUT_KEYS[0]}
The last echo just echos the end of the tag > A little confused on how arrays should be working in shell or if there is a better way to approach this.
My XML looks like this.
<?xml version="1.0" encoding="UTF-8" ?>
<strings version="5.6051.4-en">
<!--<StarLineUI>-->
<!-- Menu -->
<string key="betProper" value="Bet" fonts="uiAccountTitle" />
<string key="linesProper" value="Lines" fonts="uiAccountTitle" />
<string key="spinsProper" value="Spins" fonts="uiAccountTitle" />
<string key="bet" value="BET" fonts="uiMenuTitle, uiAccountTitle" />
<string key="line" value="LINE" fonts="uiMessage" />
</strings>
I'm trying to build a solution that works with GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
for. See BashFAQ #1 for best-practice on reading line-oriented input.indexin one place andINDEXin the other; best-practice is lowercase; see fourth paragraph of pubs.opengroup.org/onlinepubs/9699919799/basedefs/… for naming conventions).xmllint --shell.readarray/mapfileis the more sensible way to populate your array w/ values here.