Domanda

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

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

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top