I'm updating a bash script which serves as a program testing tool.
Previously, I had this line in a script working perfectly ($BIN_FILE
is set to a relative path to the binary being tested):
$BIN_FILE $BIN_OPTS &> $LOG_FILE
Then I've decided to add some "performance measurements":
time $BIN_FILE $BIN_OPTS &> $LOG_FILE"
This worked perfectly as well, but when running many tests at once, script's output was too crowded with all those "real, user, system". Now I'm passing a second parameter to the script, which causes $TIME variable to have value 'time' assigned to it. However,
$TIME $BIN_FILE $BIN_OPTS &> $LOG_FILE
just doesn't work. The only working option seems to be
eval "$TIME $BIN_FILE $BIN_OPTS &> $LOG_FILE"
but it's ugly.
Why doesn't
$TIME $BIN_FILE $BIN_OPTS &> $LOG_FILE
work? Is there a nicer-looking solution, then the one with eval?
Also, regarding portability - should I use bash's internal 'time', or call GNU /usr/bin/time?