If you experiment with redirecting the output of commands to files, you may find that error messages are still written to your terminal instead of the destination you specified:
$ grep pattern myfile /nonexistent > matches grep: /nonexistent: No such file or directory
This is an intentional design feature of Unix-like operating systems, not just the bash program; it's to separate the output of commands (standard output, or stdout) from any error messages the command may also generate (standard error, or stderr). It's very common for commands to emit both output and error messages, so that the person running the script can read the errors without it interfering with any output from the script.
If you want to redirect error messages as well, the syntax is slightly different; you need to link the redirection operator with the standard error stream's file descriptor number, which is always 2:
$ grep pattern myfile /nonexistent > matches 2> errors $ cat errors grep: /nonexistent: No such file or directory
Visually, we could present it like this:
Note that just like redirecting standard output, the file will always be created, even if there is no error output. Also note that you can use 2>> to append error output to a file; this is a useful way to keep a permanent error log for a script, because old errors in the file will not be overwritten the next time the script is run.