-1

I want change i/o of the time command, lake the following commands, but they are wrong and do not work. How to do this correctly?

time echo hello > log

bash -c 'time echo hello' > log

echo $(time echo hello) > log

  • 1
    Read man test. test does not read STDIN, does not write STDOUT or STDERR, it just sets $? ($STATUS). What do you want to change? – waltinator Jun 10 '23 at 14:26
  • @waltinator if the OP is using bash, then help test is likely more pertinent than man test. AFAIK both the bash shell builtin test and external /usr/bin/test do write to the standard error stream (and will do so in this case ex. test: echo: unary operator expected or /usr/bin/test: missing argument after ‘hello’). – steeldriver Jun 10 '23 at 14:35
  • 1
    The bash > operator only redirects the standard output stream - if you want to redirect standard error to a file, see this similar question Command output is not redirected to file – steeldriver Jun 10 '23 at 14:37
  • I'm so sorry. test no. TIME – UnitedKingdom Jun 10 '23 at 17:28

1 Answers1

-1

time (sleep 1 ; echo hello >log1) 2>log2

knu
  • 69