14

In llvm 3.0 test-suite, I am getting the following error on bash:

sh: time command not found

The code is:

if [ "x$RHOST" = x ] ; then
  ( sh -c "$ULIMITCMD $TIMEIT -p sh -c '$COMMAND >$OUTFILE 2>&1 < $INFILE; echo exit \$?'" ) 2>&1 \
| awk -- '\
BEGIN     { cpu = 0.0; }
/^user/   { cpu += $2; print; }
!/^user/  { print; }
END       { printf("program %f\n", cpu); }' > $OUTFILE.time

where $TIMEIT = time.

I tried to change sh -c to eval but the error continued.

While trying to solve this error, I noticed something funny that may or may not help solving this:

Running sh -c "time" works but sh -c "time -p" doesn't.

Do any of you guys have any idea why this error happens and how would I solve it?

5
  • Check man time and see if your implementation of time lacks the -p flag. That said, even if the flag was the problem, the error should then be -p: command not found not time not found. All that said, are you sure your system's sh is pointing to bash? If you're on some operating systems, it may be dash. (Again, not sure that helps unless dash lacks a time built-in and you have no separate time command.)
    – Telemachus
    Apr 29, 2012 at 14:26
  • "sh: time command not found" - is that the exact error message? Also, what output does readlink -f "$(which sh)" generate for you? Apr 29, 2012 at 17:18
  • The "exact" error is: sh: time: command not found
    – Rafael
    Apr 29, 2012 at 18:58
  • readlink -f "$(which sh)" outputs /bin/bash
    – Rafael
    Apr 29, 2012 at 18:59
  • Check man time and see if your implementation of time lacks the -p flag. -> Using time -p works normally. The problem is when executed together with sh -c. eval "time - p" works though normally. But in the context of the script I'm executing it seems to not work (gives the error that the time command was not found)
    – Rafael
    Apr 29, 2012 at 19:01

2 Answers 2

14

time is a reserved word in shells. To use the actual command, try:

command time [options] [command]

or:

/usr/bin/time [options] [command]

Source:

2
  • 7
    The program is provided by 'time' package: apt-get install time
    – jonhattan
    Jul 12, 2018 at 7:08
  • 1
    If you are on gentoo and receive this error, you will want sys-process/time Oct 1, 2018 at 19:15
1

The program is provided by time package.
Install it, for example, like so:

apt-get install time

This answer enshrines the comment by jonhattan.

NOTE:

I found this fix useful when I was using GitHub Actions with a script that used time -p. So I did this in the yml file:

      - name: Install other packages
        run: |
          apt-get update
          
          # `time -p` is used for benchmarking tests.
          # This fixes error: 'sh: 1: time: not found':
          apt-get install time
      - name: Set up test database and run tests
        run: |
          script_with_time.sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .