Hi there. I'm struggling to parse the output of the time command in bash - and even to stop it from printing out its output when I call it. This is my test code:
#!/bin/bash
TIME=`time ls -lh > /dev/null`
echo "Testing..."
echo $TIME
This currently prints out:
{blank-line}
real 0m0.064s
user 0m0.002s
sys 0m0.005s
Testing
{blank-line}
So, it seems like the value assigned to $TIME
is the blank line at the start of the time print-out. I need to get at the seconds value of the sys line - that is, the "0.005". I am guaranteed that I will only ever have seconds, so I do not need anything before the "m" - however, the seconds part may be in the form of xx.xxx if it goes >= 10 seconds. I currently have no idea how to suppress the 'time' output, capture it all instead of the blank line, nor parse it to get the values I need.
Any help would be much appreciated...