cat < file
prints the contents of file to stdout.
cat > file
reads stdin until Ctrl+D is detected and the input text is written to file.
cat <> file
, at least in my version of Bash, prints the contents of file happily (without error), but doesn't modify the file nor does it update the modification timestamp.
How does the Bash standard justify the seemingly ignored >
in the third statement - and, more importantly, is it doing anything?
4<>file
) is useful, and I suppose 0 is as good a default as any when you leave it out. Reading from stdout isn't any better. – Michael Homer Oct 27 '14 at 05:491<> the-file
often is as it also does not truncate the-file.<>
was introduced by the Bourne shell, so would work in any Bourne-like shell. – Stéphane Chazelas Oct 27 '14 at 07:20<>
is also useful on some systems (like Linux) to open named pipes without blocking until another process opens it for writing. – Stéphane Chazelas Oct 27 '14 at 10:59open("/dev/tty")
. That prevents users from disabling it (by using2> /dev/null
) (withopen("/dev/tty")
as well though). – Stéphane Chazelas Oct 27 '14 at 15:44stdin
,stdout
andstderr
file descriptors must be 0, 1 and 2 respectively when a program starts: http://pubs.opengroup.org/onlinepubs/009695399/functions/stdin.html – Michael Burr Oct 28 '14 at 06:34<>
operator could be useful in writing an application that worked with several terminals, and occasionally wanted to start up a shell. That shell would in turn be unable to run applications that run from an ordinary controlling terminal unless it could make use of<>
... such as ... the pagermore
, which reads from standard error to get its commands, so standard input and standard output are both available for their usual usage.cat food | more - >/dev/tty03 2<>/dev/tty03
– mikeserv Oct 28 '14 at 11:26<>
until quite late for some. – Stéphane Chazelas May 30 '17 at 21:51