Two ways to display elapsed time in bash
Contents
The hard way: use bash arithmetic
for N in $(seq 5) { do eval "$(date +'S1=%s N1=%N')" echo -n "some-command: " some-command eval "$(date +'S2=%s N2=%N')" S1="$S1$N1"; S2="$S2$N2"; CENTI_E=$(((S2-S1+5000000)/10000000)) # Can't use "$((CENTI_E/100)).$((CENTI_E % 100))" '102' returns '2' on # the '%' operation, so the result gets displayed as '1.2' # Also can't use '${CENTI:-2}': bash doesn't do negative starts (although # it can do negative lengths) FULL_S=$((CENTI_E/100)); L=${#FULL_S} echo "$FULL_S.${CENTI_E:$L} seconds" done
The easy way: use TIMEFORMAT
TIMEFORMAT="%2R seconds" echo -n "some-command: " time some-command