thatgeeman
thatgeeman

Reputation: 13

Bash Scripting : How to loop over X number of files, take input and write to a file in the same line

So I have a program written in C that takes in some parameters: calling it allcell some sample parameters: -m 1800 -n 9 the files being analyzed: cfdT100-0.trj, cfdT100-1.trj, cfdT100-2.trj, cfdT100-3.trj, ... cfdT100-19.trj file being fed: template.file out file: result.file

 $ allcell -m 1800 -n 9 cfdT100-[0-19].trj < template.file > result.file

But when I htop, I see that only cfdT100-0.trj, cfdT100-1.trj and cfdT100-9.trj are being read. How do I make the shell read all the files from 0-19 ?

Additionally, when I write a script file to automate this, how should I enclose the line? Will this work:

"$($ allcell -m 1800 -n 9 cfdT100-[0-19].trj < template.file > result.file)"

Upvotes: 1

Views: 89

Answers (2)

Lakshmanavaradhan
Lakshmanavaradhan

Reputation: 21

use recursion function for infinite loop

a()
{
echo "apple"
a
}
a

This the will make a infinite loop

Upvotes: 0

Nicola Worthington
Nicola Worthington

Reputation: 548

I believe you want to change your glob expression to cfdT100-{0..19}.trj instead.

[email protected]:~ $ echo cfdT100-{0..19}.trj
cfdT100-0.trj cfdT100-1.trj cfdT100-2.trj cfdT100-3.trj cfdT100-4.trj cfdT100-5.trj cfdT100-6.trj cfdT100-7.trj cfdT100-8.trj cfdT100-9.trj cfdT100-10.trj cfdT100-11.trj cfdT100-12.trj cfdT100-13.trj cfdT100-14.trj cfdT100-15.trj cfdT100-16.trj cfdT100-17.trj cfdT100-18.trj cfdT100-19.trj

Your quoting on the scripted version looks acceptable. Just change the glob.

Upvotes: 1

Related Questions