0

I have a query

Select id, contact_name from Profile where TRIM(IFNULL(contact_name,'')) <> ''

and I am trying to pass it into a Bash script.

mysql --user abc -psomePass MyData -e "SELECT `id`,`contact_name` from `Profile` where TRIM(IFNULL(`contact_name`,'') <> ''" | while read term_id; do
done

but it doesn't like the singe quotes ''. How do I format this in the script?

I have tried

TRIM(IFNULL(`contact_name`,\'\') <> \'\'"

and

TRIM(IFNULL(`contact_name`,\") <> \""

and

TRIM(IFNULL(`contact_name`,"''") <> "''""

I am out of ideas.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116

1 Answers1

0

but it doesn't like the single quotes.

Bash on my machine is fine with single quotes:

 $ echo "SELECT id,contact_name from Profile where TRIM(IFNULL(contact_name,'') <> ''"
 SELECT id,contact_name from Profile where TRIM(IFNULL(contact_name,'') <> ''
 $
symcbean
  • 47,736
  • 6
  • 59
  • 94
  • 1
    The question had backticks that were hard to see because of formatting, and I think they cause the problem. – Benjamin W. Sep 20 '19 at 20:00
  • I figured out my own answer. mysql -u abc -pSomePass MyData -s -e "SELECT id,contact_name from Profile where contact_name <> ''" | while read -a Result; do I then looped though the Result array id=Result[0] name = result[1] etc.. – user2705495 Sep 23 '19 at 14:32