Working with the time
command, I came across a situation where I should
use the built-in time
rather than the external GNU time command /usr/bin/time
. So, how can I do this? I saw somewhere that using enable
and/or command
would help, but they didn't.
This is a use case:
watch "time ls"
which uses the external /usr/bin/time
command, which I don't want! This happens when time
invokes the internal bash function when I run time ls
on a terminal, like this:
$ time ls
Please note that the exact opposite request has been answered here:
There is a lot of difference with two commands. The internal time
is more precise (which I want), but the external command has more options (which I do not need).
Best Answer
By default,
watch
runs your command with/bin/sh -c '...'
so the output you see is how/bin/sh
interprets thetime
command. Your/bin/sh
apparently doesn't have a builtintime
.To run the command with a different shell, use the
-x
option to get rid of the default, then add your own explicit invocation of the shell whose builtin you want.No matter how you run
watch
, the command you're watching is not a child of the shell that ran thewatch
command, so that shell's settings aren't directly relevant.