Worldcup database command not found error in the terminal

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

Not sure if this will answer your question. What command did you use? Did you make your file executable with chmod +x yourfilename?

1 Like

Yes, I have given my file executable commands but it still won’t work. The terminal says there is a command not found on line 23 where I check if my variable is empty.

If you add a space before -z, would it help?

1 Like

omg yes! Also found an extra “done”

I’m still getting an error for duplicate content but I have to use my script to fix that. Thank you.