0

I do not know much bash scripting, but I know the task I would like to do would be greatly simplified by it. I would like to test a program against expected output using many test input files.

For example, I have files named "input1.txt, input2.txt, input3.text..." and expected output in files "output1.txt, output2.txt, output3.txt...". I would like to run my program with each of the input files and output a corresponding "test1.txt, test2.txt, test3.txt...". Then I would do a "cmp output1.txt test1.txt" for each file.

So I think it would start like this.. roughly..

for i in input*;
do
    ./myprog.py < "$i" > someoutputthing;
done

One question I have is: how would I match the numbers in the filename? Thanks for your help.

2
  • ask @anubhava ... he can answer Commented Feb 10, 2014 at 8:08
  • @MortezaLSC: I believe OP accepted the answer below as it worked well for the problem posted. Commented Feb 10, 2014 at 8:10

1 Answer 1

1

If the input file name pattern is inputX.txt, you need to remove input from the beginning. You do not have to remove the extension, as you want to use the same for output:

output=output${i#input}

See Parameter Expansion in man bash.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.