管多个命令一个命令 [英] Pipe multiple commands to a single command

查看:123
本文介绍了管多个命令一个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能管多条命令的标准输出到一个命令?

例1:组合和排序的所有三个回声命令的输出:

 回声ZZZ;回声AAA;回声KKK

所需的输出:

  AAA
KKK
ZZZ


例2:改写以下,使所有的命令都在使用管道一个命令行,没有可重定向到临时文件:

  SETOPT>的/ tmp / foo的; unsetopt>>的/ tmp / foo的;集>>的/ tmp / foo的;排序的/ tmp / foo的|减


解决方案

使用括号()'s到命令组合成一个单一的过程,这将连接他们每个人的标准输出。

实施例1:

  $(回声ZZZ;回声AAA;回声KKK)|分类
AAA
KKK
ZZZ



实施例2:

 (SETOPT; unsetopt;集)|分类

How can I pipe the stdout of multiple commands to a single command?

Example 1: combine and sort the output of all three echo commands:

echo zzz; echo aaa; echo kkk

desired output:

aaa
kkk
zzz


Example 2: rewrite the following so that all the commands are in a single command-line using pipes, without redirects to a temp file:

setopt > /tmp/foo; unsetopt >> /tmp/foo; set >> /tmp/foo; sort /tmp/foo | less

解决方案

Use parentheses ()'s to combine the commands into a single process, which will concatenate the stdout of each of them.

Example 1:

$ (echo zzz; echo aaa; echo kkk) | sort
aaa
kkk
zzz


Example 2:

(setopt; unsetopt; set) | sort

这篇关于管多个命令一个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆