Bash increment input file name -


I am trying to write a better bid script to run the specified program repeatedly with different input files. This is the original Cruelty Force version that works, but I want to be able to use a loop to change the argument before ".txt".

  #! / Bin / bash ./a. 256.txt & gt; & Gt; Output.txt ./a.out 512.txt & gt; & Gt; Output.txt ./a.out 1024.txt & gt; & Gt; Output.txt ./a.out 2048.txt & gt; & Gt; Output.txt ./a.out4096.txt & gt; & Gt; Output.txt ./a.out 8192.txt & gt; & Gt; Output.txt ./a.out 16384.txt & gt; & Gt; Output.txt ./a.out 32768.txt & gt; & Gt; Output.txt ./a.out 65536.txt & gt; & Gt; Output.txt ./a.out 131072.txt & gt; & Gt; Output.txt ./a.out 262144.txt & gt; & Gt; Output.txt ./a.out 524288.txt & gt; & Gt; Output.txt  

I tried to create a loop and change the argument:

  #! For / bin / bash arg = 256 ((i = 1; i  

But me. Receives an error on /et.out./ ".txt" that does not exist. What is the correct way of raising the args in the power of me and to use it as the argument of ./a.out?

This is all you have to do:

  ((I = 256; i & lt; = 524288; i * = 2)); Do ./a.out "$ i.txt"; Did & gt; Output.txt  

Each time the loop repeats, i is multiplied by 2, which produces the sequence you want. Instead of redirecting the output of each drive individually to the file, I also took the redirection outside the loop. In this way, the file will contain only the contents of the loop.

In your question, $ args is empty (I think you have $ arg ), so your file name is just .txt . In addition, you have & lt; & Lt; & gt; & Gt; , which I assumed.


Comments