惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
D
DataBreaches.Net
S
Secure Thoughts
B
Blog
S
Schneier on Security
Y
Y Combinator Blog
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cyber Attacks, Cyber Crime and Cyber Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
F
Full Disclosure
Engineering at Meta
Engineering at Meta
L
LangChain Blog
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Hacker News
The Hacker News
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
雷峰网
雷峰网
博客园 - 司徒正美
Help Net Security
Help Net Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Privacy International News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threat Research - Cisco Blogs
Recent Announcements
Recent Announcements
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Heimdal Security Blog
Jina AI
Jina AI
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
Microsoft Security Blog
Microsoft Security Blog
L
Lohrmann on Cybersecurity
aimingoo的专栏
aimingoo的专栏
D
Docker
I
Intezer
C
Check Point Blog
Cloudbric
Cloudbric
小众软件
小众软件
V2EX - 技术
V2EX - 技术

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事 blockly与结对编程
[译]对管道(Pipes)的偏爱
种瓜 · 2019-01-23 · via 夜行人

原文链接:For the Love of Pipes

早上在hacker news上读到一篇短文,来自Jessie Frazelle的博客(Jessie Frazelle是Github团队成员).

文章写得简短清晰,顺手翻译过来。

译文

我最常用的shell命令是|。它被称为管道(pipe)。

简而言之,|允许一个程序(左侧)的输出成为另一个程序的输入(右侧)。这是一种将两个命令连接在一起的方法。

例如,如果我运行以下内容:

echo "hello"

输出为hello

但如果运行:

echo "hello" | figlet

figlet程序改变了hello中每个字母的外观,看起来像卡通风格。

1
2
3
4
5
6
7
8
:::text

➜  scratch_backend git:(master) echo "hello" | figlet
 _          _ _
| |__   ___| | | ___
| '_ \ / _ \ | |/ _ \
| | | |  __/ | | (_) |
|_| |_|\___|_|_|\___/

这是一种非常直观的描述某些东西的方式。在我看来,这是一种优秀的软件设计。

让我们回到管道的起源。

根据doc.cat-v.org/unix/pipes/,管道早在Unix之前就已存在。管道可以追溯到1964年Doug McIlroy的这篇笔记:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
:::text


            - 10 -
    Summary--what's most important.

To put my strongest concerns into a nutshell:

1. We should have some ways of coupling programs like
garden hose--screw in another segment when it becomes when
it becomes necessary to massage data in another way.
This is the way of IO also.

2. Our loader should be able to do link-loading and
controlled establishment.

3. Our library filing scheme should allow for rather
general indexing, responsibility, generations, data path
switching.

4. It should be possible to get private system components
(all routines are system components) for buggering around with.

                                                M. D. McIlroy
                                                October 11, 1964 

Doug McIlroy将Unix哲学记录为:

  1. 让每个程序做好一件事。如果要完成一个新任务,重新构建而不是通过添加新的“功能”使旧程序复杂化。
  2. 期望每个程序的输出成为另一个尚未知的程序的输入。不要使用无关信息来污染输出。避免严格的柱状或二进制输入格式。别坚持使用互动输入。
  3. 设计和构建软件,甚至是操作系统,要尽早尝试,最好在几周内完成。毫不犹豫地扔掉笨拙的部分并重建它们。
  4. 使用工具让编程任务变轻松,即使你得先去构建这些工具,用完之后你还可能抛弃它。

来自贝尔系统技术期刊

我喜欢Unix的是“做好一件事”和“期望每个程序的输出成为另一个程序的输入”的理念。这种理念建立在工具的使用上。这些工具可以单独使用,也可以组合在一起使用以完成工作。这与用于解决特定问题的大一统/一次性的专用程序形成鲜明对比。

我们在上面看到的系统程序/命令:echo 默认将信息输出到终端。cat将“连接”(它的同名)文件并将结果打印到终端。在阅读Unix程序设计时,我意识到将工具的输出打印到用户终端实际上​​是特例。

“也许令人惊讶的是,在实践中,事实证明特例是该程序的主要用途。”

当用户将cat的输出通过|重定向到其他程序时, cat变得比原作者想要的更为强大。在我看来,这是最精彩的设计模式之一。一方面,程序变得十分简单,做好一件事的原则让它们轻易制作。更有趣的是,通过与|操作符结合,程序成为更大规划中的一步。cat的原作者甚至不需要了解更大的计划。这就是|的美妙之处, 它可以通过将小而简单的程序组合在一起来解决问题.

我喜欢这样的软件设计,它鼓励创造,认可简单的价值,并且不会将用户放在盒子里。管道是保持程序简单同时实现可扩展性的关键元素。一个简单的程序通过与|结合, 能力远远超出原作者梦寐以求的程度。

希望本文可以帮助你学习一些东西,如果它没做到,只需要把它pipe到/dev/null

译者注

如果你对管道有更多兴趣,推荐阅读《Unix编程艺术》