Solution and Explanation:
problem2.sh
#!/usr/bin/env bash
# output file name for stdout
FILEOUT='test.out'
echo $FILEOUT
# output file name for stderr
FILEERR='test.err'
echo $FILEERR
# opening test.in and pipe to cmd1 and output of cmd1 pipe to cmd3 and giving file for stdout and stderr
cat test.in | ./cmd1 | ./cmd3 > $FILEOUT 2>$FILEERR
# END OF SCRIPT
# NOTE: it is to make sure all files in same directory including test.in
After running problem2.sh
$ ./problem2.sh
test.out
test.err