Struggling to parse (bash) time command

后端 未结 5 771
甜味超标
甜味超标 2020-12-07 00:55

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:

#!/b         


        
5条回答
  •  青春惊慌失措
    2020-12-07 01:07

    If you use the Bash builtin time, you can control its output by setting the TIMEFORMAT variable:

    TIMEFORMAT=%R
    

    and you won't have to do any parsing since that will cause time to only output the number of seconds.

    and use this:

    echo "Testing..."
    TIME=$( { time ls -lh > /dev/null; } 2>&1 )
    echo $TIME
    

    or one of the other techniques from BashFAQ/032.

提交回复
热议问题