The differences between Unix echo and DOS types show the differences in the software design philosophy between operating systems.

Source: Internet
Author: User

Write by jtianling )--
Blog.csdn.net/vagrxie

Discuss newsgroups and documents

This article is only written
Summary of various process creation methods (MacOS, Win32, Linux, QT,
Python……) When I found that there was a problem with inserting a large segment of irrelevant text, I just stripped it out. This is also a reconstruction of the article .....
From UNIX echo
Commands and DOS type commands are basically used to display the file content, but they are roughly the same, but there are some minor differences, I was quite touched, so
It's a bit boring. However, two small commands show two different worlds.

Comparison methods

1,
The simplest process is to create a process with parameters. The following example shows the content of file a and file B in the current directory.

2. display the process's output redirection usage to direct files A and B in the current directory to file C as an example.

3. display the pipe communication technology between processes to pass files A and B in the current directory to another output process through the pipeline and display them.

(Test1, 2, 3 ).
The preceding three operations show the differences between ECHO and type.

Test1:

1.
Let's start with the simplest method. We will take bash in Unix as an example.

Jtianling $ echo "I'm File ."
>
Jtianling $ echo "I'm file B."> B
Jtianling $ ls
A
B
Jtianling $ cat
I'm file.
Jtianling $ Cat B
I'm file B.
Jtianling $
Cat A B
I'm file.
I'm file B.
Jtianling $
Okay, Cat
B. In this simple call, the process is created, the parameter input is complete, and the display is normal.


Test2:

2. Output redirection.
Shell is really a small case, it can be said to be its native.

Tianlings-MacBook: Test jtianling $ cat
A B> C
Jtianling $ cat c
I'm file.
I'm file B.
Jtianling $

Cat a B> C.


Test3:

3. pipeline or shell rice bowl
.

Jtianling $ cat a B | cat
I'm file.
I'm file B.
Cat
A B | cat is just a piece of code.


Comparison of type in DOS:
Test1:


DoS
You can also use the type command to try it once as described above:

Test1 is basically available, that is, output, but in fact, take a closer look at
TYPE command, you will find that the output is somewhat different:

F:/mysrc/testprocess> type A B

A

I'm
File.

B

I'm file B.


Intuitively, type
B Automatically releases files a and B to you by file name. What kind of humanization? Haha, but obviously we can see the culture of DOS developers (Special to Ms ?) Poor culture with the Unix community
Exception. in UNIX, the command line program is recommended not to output nonsense (such as A, B, and typographical), so that it can be used by other programs through pipelines or redirection, DOS seems to advocate direct
Look .......


Test2:

It is found that although the direct output has additional output
Processing is performed during targeting:

F:/mysrc/testprocess> type a B> C

A

B

F:/mysrc/testprocess> type
C
I'm file.
I'm file B.

The redirected result is displayed with Cat a B>
C is exactly the same. However, the format of A and B is output, indicating that the output of A and B is not a standard output channel. So what is left? Standard Error channel... Let's test it.

> Type
A B 2> d
I'm file
I'm file B

> Type D

A

B

>


Result
In this case, when the error channel is relocated to file D, you can see that the output is simplified, and the content in D is the additional output. Using more complex hack techniques (using error output
To output normal information. In short, it is not a good method.) In fact, implementation is not too necessary, but a bit of a useful task. If it is good or bad, it depends on your opinions.


Test3:

Yes
It is found that type cannot accept standard input, that is, it cannot form | type chain call, just like cat a B | cat.

This will cause
Test3 cannot be completed using type. This is also a cultural difference... because of the UNIX shell usage habits, pipeline and relocation are almost essential cooperators for command lines.
With, DOS/Windows programs do not have this tradition, so you can understand it without implementation. Furthermore, Win32
The API does not even have any direct support for pipeline and input/output redirection, because it does not seem to care about it at all, while the POSIX pipe and popen support relevant use is very convenient.
Quick. (Of course, there are also some implementations of POSIX functions in windows, including pipe and popen, but add a slide line before naming)


Small
Conclusion:

Therefore, for the type name, the description is: TYPE Displays the contents of a text file.

Pair
In cat command, man is described as: concatenate file (s), or standard input, to standard
Output.

In addition, check the cat parameters and you will find that cat actually has many custom functions, but what about type? It is estimated that only /? Parameters
............

In the past, Unix relied heavily on Shell (previously only shell), along with its cultural influence and work needs
Shell commands are powerful and highly collaborative (because of the old rules). The most typical of them is find. grep will know when you try it. In addition
.... So what about Perl and python ?...... Oh, it's far away.




 

Reserved version of original article author
For permission reprint, please indicate the original author and give a link

Write by jtianling )--
Blog.csdn.net/vagrxie

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.