1

Is there any difference between (# comments taken from documentation)

command > filename  # Docs: Redirect stdout to a file.

and

command 1> filename # Docs: Redirect stdout to file "filename."
1

From the Bash manual's section on Redirection (emphasis mine):

Redirection of output causes the file whose name results from the expansion of word to be opened for writing on file descriptor n, or the standard output (file descriptor 1) if n is not specified. If the file does not exist it is created; if it does exist it is truncated to zero size.

So, there is no difference between >foo and 1>foo.

1

Standard output is the implicit file descriptor if it isn't listed, so they're effectively the same thing. Using 1> is not a style that I've ever seen.

% grep _FILENO /usr/include/unistd.h 
#define  STDIN_FILENO   0       /* standard input file descriptor */
#define STDOUT_FILENO   1       /* standard output file descriptor */
#define STDERR_FILENO   2       /* standard error file descriptor */
  • How does the shell use unistd.h? – John_West Mar 17 '16 at 23:44
  • 1
    The shell and most if not all programs are compiled with unistd.h. – Law29 Mar 18 '16 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.