Abhishake Yadav Abhishake Yadav - 1 month ago 21
Bash Question

using sqlite3 in for loop in shell script gives error

Need to query a certain value from each file in a directory and put it in a file. I use the code:

#!/bin/bash

ls -lrt | grep -w "458752" | awk '{print $9}' | sort -V > list

for linename in cat list
do

/d/home/alima0152/Desktop/sqlite3 $linename "select trace_count from volume"; >> trc_count

done

rm list


But I get this error:


file is encrypted or is not a database

CL. CL.
Answer

This code is trying to open the files cat and list.

To execute something and insert its output, use `...` or $(...):

for linename in $(cat list)