加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 以“>”开头的Shell命令

发布时间:2020-12-16 01:09:18 所属栏目:安全 来源:网络整理
导读:我最近遇到了一个看起来像这样的 shell命令:“ outfile infile cat”,它似乎在功能上等同于“cat infile outfile”.就此而言,一般形式似乎是“ outfile infile命令arg1 ... argN”变为“命令arg1 ... argN infile outfile”. 无论如何,我想知道是否有人可以
我最近遇到了一个看起来像这样的 shell命令:“> outfile< infile cat”,它似乎在功能上等同于“cat infile> outfile”.就此而言,一般形式似乎是“> outfile< infile命令arg1 ... argN”变为“命令arg1 ... argN infile> outfile”.

无论如何,我想知道是否有人可以详细说明领先的“>”实现这种效果,如果有任何实际用途.

“Bash Reference Manual”说明了重定向运算符:

The following redirection operators may precede or appear anywhere within a simple command or may follow a command.

所以以下命令都是等效的:

ls -al > listing.txt
> listing.txt ls -al
ls > listing.txt -al

虽然我猜第一种是最常见的形式.

请注意,重定向的相对顺序很重要,因此,例如,如果要将一个文件描述符重定向到另一个文件描述符,则以下内容会有所不同:

ls > listing.txt 2>&1   # both stdout and stderr go in to listing.txt

ls 2>&1 > listing.txt   # only stdout goes to listing.txt,because stderr was made
                        #    a copy of stdout before the redirection of stdout

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读