K.I.S.S 原则

更新日期: 2017-05-10 阅读次数: 8019 分类: Linux

(./first_tool | ./second_tool) < input_file.txt > output_file.txt

加括号是为了保证 input_file.txt 的内容能够通过 stdin 传递给 first_tool,而不是 second_tool.

Ask: Ah, I see. And do you deal with a lot of tools?

Answer: Arn’t that life? It depends on the operating system. Unix-style systems use a lot of tools to get the work done.

Ask: Creating small tools that work together is almost a philosophy, isn’t it?

Answer: It’s a way of life. Sometimes when you’ve got a big problem to solve, it can be easier to break it down into a set of simpler tasks.

Q: Why is it important that small tools use the Standard Input and Standard Output?

A: Because it makes it easier to connect tools together with pipes.

Q: So if two programs are piped together, does the first program have to finish running before the second program can start?

A: No. Both of the programs will run at the same time; as output is produced by the first program, it can be consumed by the second program.

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式