0

In a BASH script, I am reading in a list of strings from a text file that may contain apostrophe ('). Each string in the list is saved to a BASH environment variable that is passed to my psql query. I have tried everything so far but still when I loop through the list, if I counter an apostrophe, my query fails.

Here is a snipit of the code that fails:

SELECT * FROM table_1 WHERE id = $myid AND name = '$namelist';

namelist is the file that has the entries which may contain apostrophes.

Thanks for you help

nKognito
  • 6,297
  • 17
  • 77
  • 138
hhf
  • 1

1 Answers1

0

Use a prepared SQL statement to avoid SQL injection.

You may also need a solution from this post.

Community
  • 1
  • 1
Shadowen
  • 838
  • 5
  • 14