I am trying to read out ids from mysql and then delete the entry with id-1.
today_time=$(date -d "now" '+%d-%b-%Y %H:%M:%S')
query_find_id="SELECT id FROM guestlist WHERE value <= '$today_time'"
array_query=$(mysql -u $USER -p$PASSWORD $TABLE_NAME -e "$query_find_id")
array_id=($(for i in $array_query; do echo $i; done))
for j in "${array_id[@]}"; k=$j-1; mysql -u $USER -p$PASSWORD $TABLE_NAME -e "DELETE FROM guestlist WHERE id = '$k'"; done
The array is empty every time. What am I doing wrong?
set -vxand examine the output from each line. You would probably see thatquery_find_idis empty when you get to the 3rd line. (Agreeing about answer from @tgx.) Good luck to all.