0

For example, if I have a statement:

/home/1/test.sh > /home/1/test.log 2>&1

What does the last part of this do effectively?

Thanks.

Mdev
  • 119
  • @Freddy Yes, I didn't realize google had added symbols as meaningful search terms, that's my bad. Makes looking these things up a lot easier. Someone can close this question. Thanks! – Mdev Mar 11 '21 at 23:50

1 Answers1

1

Greater than or 1 greater than means redirect stdout (standard output, what's usually written to the terminal. 2 greater than means redirect stderr (standard error).

In 2>&1, you are redirecting stderr AND (ampersand) stdout.

  • In this case, where are you redirecting it to? Thanks! – Mdev Mar 11 '21 at 23:45
  • 1
    In the example you gave, you'd be redirecting it to the filename following >, so /home/1/test.log. Note that there is a more readable but less portable version of the above: /home/1/test.sh &> /home/1/test.log. – Grace Thompson Mar 11 '21 at 23:46
  • Oh okay, I think I understand. So it's redirecting stdout to the file, then redirecting stderr to stdout, which is being redirected to the file, so both stdout and stderr are redirected to the log file. Is that correct? – Mdev Mar 11 '21 at 23:49
  • 1
    Yes, that's right. – Grace Thompson Mar 11 '21 at 23:51
  • 2
    2>&1 as such doesn't redirect stderr and stdout, though (that's what &> does). It redirects stderr to wherever stdout is pointing at that moment. – DonHolgo Mar 12 '21 at 10:26