I am writing a script for competitive programming judging and here is part of the bash script:
#!/bin/bash
TIMEFORMAT=%S
if [ $1 = "-cpp" ]; then
output1=$(g++ -std=c++17 -O2 -Wall -fsanitize=address -lm -s -x c++ b.cpp && ./a.out < input1)
expected1=$(< output1)
time1=$(time g++ -std=c++17 -O2 -Wall -fsanitize=address -lm -s -x c++ b.cpp && ./a.out < input1)
if [[ -z "$expected" ]]; then
echo "Test Case #1 - Passed! Time: ${time1} sec"
elif [ $output1 = $expected1 ]; then
echo "Test Case #1 - Passed."
else
echo "Test Case #1 - Failed (check 'dump1.log' for details)."
fi
fi
The output for the C++ program is 15. The output of the bash script is:
0.172
Test Case #1 - Passed! Time: 15 sec
It prints the time output above the actual point of concatenation. And in the place of concatenation, it prints the actual C++ output. I am extremely new to bash so I don't know what is going on.