Problem 1: I need to make a loop and if I use for it loops forever. Below I have put the part of the script that works and at the bottom the section I need to loop
#!/bin/bash
#Input War Players
read -r -p "Number of Players " Players
read -r -p "Player 1 Name " Player1
if [ "$Players" -gt 1 ]; then
read -r -p "Player 2 Name " Player2
fi
if [ "$Players" -gt 2 ]; then
read -r -p "Player 3 Name " Player3
fi
WarPlayerList="$Player1","$Player2","$Player3"
Up to here works from here is the loop that doesn't
for i in $WarPlayerList
do
TH=""
while [[ ! "$TH" =~ ^[0-9] ]]; do
echo "Enter Player TH Level "
read TH
done
done
I need this to loop for every player I enter eg 3. Then I need to output each players data in separate variables to use below command:
#Output Results to File
Headers=("Player","Attacks","Stars","Damage","Stars Earned","3 Star Rate","Points")
Player1Results=("$Player1","$Attacks1","$StarResult1","$DamageResult1","$StarEarnedResult1","$StarRate1","$PointsResult1",)
Player2Results=("$Player2","$Attacks2","$StarResult2","$DamageResult2","$StarEarnedResult2","$StarRate2","$PointsResult2",)
Player3Results=("$Player3","$Attacks3","$StarResult3","$DamageResult3","$StarEarnedResult3","$StarRate3","$PointsResult3",)
printf "%s\n" "$Headers" "$Player1Results" "$Player2Results" "$Player3Results" > WarResults.csv
Some sites suggest foreach instead off for
While I'm on the subject of asking for help, I need this piece of code to check if the input matches up, down or opposite:
Problem 2:
PositionA=""
while [[ ! "$PositionA" =~ "up | ! "$PositionA" =~ "down" | ! "$PositionA" =~ "opposite" ]]; do
echo "Enter Player Attack up, down or opposite "
read PositionA
done
Problem 3:
I need the input name to match the names in the database list otherwise it won't update MYSQL properly
Playerlist=$( awk -F "," '{ print $2 }' Database_input.csv )
Player1=""
while [[ ! "$Player1" =~ "$Playerlist" ]]; do
echo "Enter Player 1 Name "
read Player1
done
also tried:
if [ "$Player1" != .\* "$Playerlist"\ .* ]; then
read -r -p "Retype Player 1 Name " Player1
fi
Appreciate some insight.