chovy
chovy

Reputation: 75686

how do I loop over rows in an sqlite db from bash?

#!/bin/sh

rows=$(sqlite3 db 'select * from subscriptions;')

for row in $rows; do
  // curl $row['email']
done

I have a db that has email and keyword i want to make some curl requests for each row in the db.

Upvotes: 1

Views: 1400

Answers (1)

644
644

Reputation: 639

If the output is delimited by newlines, you could do

while IFS= read -r row; do
    echo "${row}"
done < <(sqlite3 db 'select * from subscriptions;')

Or you could read the rows into an array first, and iterate over it

mapfile -t rows < <(sqlite3 db 'select * from subscriptions;')
for row in "${rows}"; do
    echo "${row}";
done

Upvotes: 2

Related Questions