0

I have seen this command

(echo "hello world" >> /var/log/hello.txt") 2>&1

Usually if I wanted to log out errors in case a command failed e.g the echo command for example, I'd do:

echo "hello world" 2>/var/log/hello-error.log

And if I wanted to log out both stdout and stderror, I'd do:

echo "hello world" &>/var/log/hello-out-and-error.log

And if I didn't care where these logs went, I'd log them to /dev/null for example

echo "hello world" 2>/dev/null

However, recently, I've come accross this notation and not sure what it means:

(echo "hello world" >> /var/log/hello.txt") 2>&1

What does the notation

2>&1

mean?

Are we grabbing stderror and logging it out to stdout? Even saying it doesn't seem to make sense

pelican
  • 5,846
  • 9
  • 43
  • 67
  • 1
    Possible duplicate of [How to pipe stderr, and not stdout?](https://stackoverflow.com/questions/2342826/how-to-pipe-stderr-and-not-stdout) – Sunny Patel Aug 01 '18 at 16:47
  • Possible duplicate of [In the shell, what does " 2>&1 " mean?](https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean) – tk421 Aug 01 '18 at 17:15

0 Answers0