0

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.

VJZ
  • 119

1 Answers1

-3

By simply calling time, you're making use of the bash builtin. Check this with type -a time.

To use the time program, use the full path, /usr/bin/time.

Read man time bash.

waltinator
  • 4,865
  • 1
    Why is man time relevant here? That gives the manual for the binary /usr/bin/time (or whatever is installed), not for the builtin. Did you mean "read help time"? And how is this answering the OP's question about the output they are seeing? – terdon Jun 08 '21 at 13:48