World Cup Database - keep hitting error

I swear I’m going crazy. I did 100’s of these PSQL prompts but this one keeps throwing an error. I’m basically going one step at a time and just trying to get my bash script to query the database for every ‘Winner’ entry in the games.csv file.

#! /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.


IFS=","
cat games.csv | while read YEAR ROUND WINNER OPPONENT WINNER_GOALS OPPONENT_GOALS
do
  if [[ $WINNER != 'winner' ]]
    then WINNER_ID=$($PSQL "SELECT team_id FROM teams WHERE major='$WINNER'")
  fi
done

Error in question on every iteration of the loop:
./insert_data.sh: line 17: psql --username=freecodecamp --dbname=worldcup -t --no-align -c: command not found

1 Like

This line changes the IFS not only for the while’s loop reading part, but also for what’s executed in it and after it.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.