2

Refering to this question, I want something a little bit similar. The idea is that I execute a command, then it asks for a file name to process, and after it is done with processing, it asks for the next filename and so on. The problem that I have thousands of files, so I cannot enter them manually one by one. However, I have a .txt file containing all the filenames.

So I wanted to write a bash script which:

  1. execute the command
  2. when it asks about a filename, it reads the first line from the txt file
  3. the program will process the file, then asks for the next
  4. the bash gives the next and so on

until the program asks for a file, and already the .txt file is done, then I terminate automatically

  • while read file; do ./program.sh "$file"; done < list.txt – Helio Jul 30 '18 at 13:36
1

Whenever one speaks of "thousands of files", I immediately think of xargs (read man xargs). Assuming your filenames are simple (not containing blanks or other funny characters):

xargs --interactive -n 1 <filenames.txt YourProgram

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.