linux - Ordering requirement for a combination of the redirection operators < and > -


I have found that these two commands have the same output, when typing:

  1 cat & Lt; File 1 & gt; File2 2. Cat & gt; File2 & lt; File1  

It is confused whether there is an order requirement when using these redirection operators?

As Matt Macbone points out, & lt; File 1 and & gt; File2 Basically assignments are interpretted before running the command. They are very much interpreted

  input = "file1"; Output = "file2"; Cat execution  

versus

  output = "file2"; Input = "file1"; Cat execution  

Which is clearly the same.

However, in some cases the order is a matter! Cat & gt; Foo 2 & gt; & Amp; 1 :

  output = "foo"; Error = output; Cat execution  

In this case, the error and the output are identical with the comparison of the cat 2 & gt; & Amp; 1 & gt; Foo :

error = output; Output = "afu"; In this case, output is set to "foo" , while error see the default value (usually terminal) for output < / P>

This means that the first version will write both outputs and errors in one file, while the other will just write the output to a file, and any errors in the terminal:

  $ Cat nosuchfile & gt; Foo 2 & gt; & Amp; 1 (no output) $ cat foo cat: nosuchfile: Any such file or directory  

versus

  $ cat nosuchfile 2 & gt; ; 1 & gt; Foo cat: nosuchfile: Any such file or directory $ cat foo (no output)  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -