echo 0 > file.txt, with the spaces,
> file.txt causes the shell to redirect standard output so that it is written to
file.txt (after truncating the file if it already exists). The rest of the command,
echo 0, is run with the redirections in place.
When a redirection operator is prefixed with an unquoted number, with no separation, the redirection applies to the corresponding file descriptor instead of the default. 0 is the file descriptor for standard input, so
0> file.txt redirects standard input to
file.txt. (1 is standard output, 2 is standard error.) The number is treated as part of the redirection operator, and no longer as part of the command’s arguments; all that’s left is
You can see this happening more obviously if you include more content in the
$ echo number 0 > file.txt
$ echo number 0> file.txt
number shows up in the second case because standard output isn’t redirected.
This variant of the redirection operator is more commonly done with standard error,
Redirecting standard input in this way will break anything which actually tries to read from its standard input; if you really want to redirect standard input, while allowing writes, you can do so with the
cat 0<> file.txt