how to clear out std and transfer stderr to std?
I have the following command in a bash script,
开发者_高级运维time=$((./a.out) 2>&1)
When run it, there are some printout in std when running a.out alone. How to clear those printout and make $time
variable only contain execution time?
time=$(./a.out 3>&1 1>/dev/null 2>&3)
This:
redirects stderr to an unused stream (3),
silences stdout
redirects the temporary stream (3) to stdout
This is based on this answer.
精彩评论