C
C
celovec2020-09-07 10:49:17
bash
celovec, 2020-09-07 10:49:17

Parsing multiple lines in bash?

#!/bin/bash
mysql -h localhost -login -pass -Dbase -e "SELECT userID from people WHERE (login = '${LOGIN}' AND test = '${TEST}')" | while read userID; do
mysql -h localhost -login -pass -Dbase -e "DELETE from people WHERE userID = '$userID'";
done
exit


We connect to the database, see if such login and test are already in the database, delete this entry from the database.

I unfortunately do not have the opportunity to test this script. I'm concerned about the $userID variable.
BASH will understand that it needs to be taken from a mysql query?
Or maybe it's better to write such a function somehow differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-09-07
@Lynn

What's stopping you from writing

DELETE from people WHERE (login = '${LOGIN}' AND test = '${TEST}')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question