HI,
I am trying to implement a simple shell script program that does not make use of ls
or find
commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this:
-
Generate a file name using shell script, for example, 1.dat, 2.dat,..., so on.
-
Call a C program within the for-loop in that shell program. The C program reads the file name in argv [ 1 ], which is defined within the program.
-
Loop until all files have been read by the C program.
This is what I have done.
My original shell script was this:
ls -1 *.dat | while read page
do
c_program.out $page>$page.txt
done
rename .dat.txt .dat *.dat.txt
But the above script is very slow when the number of files is really really big. SO I am now trying to do this:
for i in {1..5}
do
var=`$i.dat`
c_program.out $var > $i.txt
done
rename .txt .dat *.txt
But when I run the shell script, I get the following errors:
shelll_script.sh: line 3: ./1.dat: Permission denied
shelll_script.sh: line 3: ./2.dat: Permission denied
shelll_script.sh: line 3: ./3.dat: Permission denied
shelll_script.sh: line 3: ./4.dat: Permission denied
shelll_script.sh: line 3: ./5.dat: Permission denied
I am using Linux with BASH.