echo "$(time perlscript > /dev/null)" | mawk '{ print $9 }'

returns the entire output of echo, not the ninth column as I hoped. Why?

有帮助吗?

解决方案

If you want to do something with time result you have to wrap it within a subshell and redirect stderr to stdout as follows:

$ (time sleep 0) 2>&1 | awk '{print $2}'

0m0.006s
0m0.000s
0m0.000s

Because something like this seems to be ignoring me:

$ time sleep 0 | grep real

real    0m0.011s
user    0m0.000s
sys     0m0.008s

and so does this:

$ time sleep 0 2>&1 | grep real

real    0m0.012s
user    0m0.000s
sys     0m0.004s
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top