I want to time reading bash history and put the result into a variable.
Unfortunately, time (which is a shell keyword) prints the result to stderr, and apparently redirecting stderr from shell keywords doesn't work the same as redirecting regular command output. In other words,
foo=$(time history -r 2>&1)
doesn't work (foo variable is empty, output is printed to terminal). How can I capture the output of time keyword?
Note: since history is a shell builtin, I cannot use external time command (i.e. /usr/bin/time) - I have to use time keyword in bash.