0

I have the below script. I want to execute the same query over and over again, with different dates.

The below doesn't work because it says $i is not valid

Anyone got any ideas?

Thanks

#!/bin/bash
for i in '2022/08/30' '2022/08/31'
do
    mysql --host=myhost --user=myusr --password=mypass -e 'select * from db.table where dt = $i'
done
kikee1222
  • 1,866
  • 2
  • 23
  • 46
  • 1
    Change `'select * from db.table where dt = $i'` to `"select * from db.table where dt = $i"` – Ivan Sep 04 '22 at 17:58

1 Answers1

1

The single quotes do not do variable expansion.

It should be:

mysql --host=myhost --user=myusr --password=mypass -e "select * from db.table where dt = $i"
Bib
  • 922
  • 1
  • 5
  • 10