Say in the current directory there are some files called:
test1.out, test2.out, test3.out ...
test1.expect, test.expect, test3.expect ...
I would like to compare each test.out with its corresponding test.expect, like:
diff test1.out test1.expect
diff test2.out test2.expect
and so on. I would like to know how could I achieve this more efficiently. Thank you!
I am not very familiar with linux shell. I have tried things like:
for i in *.out; do diff "$i" "$i.expect"; done
but I realize that this is not correct because $i includes the .out extension.
>Solution :
With Bash, you have a lot of powerful variations on parameter expansion. For example, in this variation on your attempt:
for i in *.out; do diff "$i" "${i/%out/expect}"; done
The "${i/%out/expect}" expands to the value of shell variable i, with the trailing out (if any) replaced by expect.
The bash man page and the bash manual are both good references for bash features and capabilities.