I should be almost on my way by now but my when I run my script it keeps telling me command not found. Is it my code (it’s pretty clean).
#! /bin/bash
if [[ $1 == "test" ]]
then
PSQL="psql --username=postgres --dbname=worldcuptest -t --no-align -c"
else
PSQL="psql --username=freecodecamp --dbname=worldcup -t --no-align -c"
fi
# Do not change code above this line. Use the PSQL variable above to query your database.
echo $($PSQL "TRUNCATE TABLE games, teams")
cat queries.sh | while IFS="," read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS
do
# get winner teamnames
# exclude first row of column identifiers
if [[ $WINNER != "winner" ]]
then
#get the team name
WINNER_TEAM=$($PSQL "SELECT name FROM teams WHERE name='$WINNER'")
# if the team not found at new team
if [[-z $WINNER_TEAM ]]
then
#insert new team
INSERT_WINNER_TEAM=$($PSQL "INSERT INTO teams(name) VALUES('$WINNER')")
#echo to check if team was added
if [[ $INSERT_WINNER_TEAM == "INSERT 0 1" ]]
then
echo $WINNER
fi
fi
fi
done
#exclude the first row of column identifiers
if [[ $OPPONENT != "opponent" ]]
then
# get the team name
OPPONENT_TEAM=$($PSQL "SELECT name FROM teams WHERE name='$OPPONENT'")
# if the opponent is not found
if [[ -z $OPPONENT_TEAM ]]
then
# insert opponent team
INSERT_OPPONENT_TEAM=$($PSQL "INSERT INTO teams(name) VALUES('$OPPONENT')")
# echo to tell us what was inserted
if [[ $INSERT_OPPONENT == "INSERT 0 1" ]]
then
echo $OPPONENT
fi
fi
fi
done