SH命令:exec 2 - ;&放大器; 1 [英] sh command: exec 2>&1

查看:287
本文介绍了SH命令:exec 2 - ;&放大器; 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会有什么这个命令怎么办?

  EXEC 2  - ;&放大器; 1


解决方案

从技术上讲它复制,或副本,标准错误到标准输出。

通常你不需要exec来执行此操作。 EXEC的文件描述符较典型的用途是指明要分配文件到一个未使用的文件描述符,例如

 EXEC 35℃ my_input 

BTW不要忘了声明的管道连接到文件时的顺序是非常重要的,所以

  LS> mydirlist 2  - ;&放大器; 1

将工作,因为它指导标准输出和标准错误输出到文件mydirlist,而命令

  LS 2  - ;&放1 GT; mydirlist

只定向标准输出,而不是标准错误,提交mydirlist,因为标准错误被做标准输出的副本之前标准输出重定向到mydirlist。

编辑:这是该外壳的作品扫描由左到右的方式。所以读第二个的话说,复制到标准错误标准输出它说之前送标准输出到mydirlist。然后阅读第一位的话说:送标准输出到文件mydirlist之前,它说:标准错误复制到该标准输出我已经设置了。我知道。这是完全不直观!

What will this command do?

exec 2>&1

解决方案

Technically speaking it duplicates, or copies, stderr onto stdout.

Usually you don't need the exec to perform this. A more typical use of exec with file descriptors is to indicate that you want to assign a file to an unused file descriptor, e.g.

exec 35< my_input

BTW Don't forget that the sequence of declaration when piping to a file is important, so

ls > mydirlist 2>&1

will work because it directs both stdout and stderr to the file mydirlist, whereas the command

ls 2>&1 > mydirlist

directs only stdout, and not stderr, to file mydirlist, because stderr was made a copy of stdout before stdout was redirected to mydirlist.

Edit: It's the way that the shell works scanning from left to right. So read the second one as saying "copy stderr onto stdout" before it says "send stdout to mydirlist". Then read the first one as saying "send stdout to the file mydirlist" before it says "duplicate stderr onto that stdout I've set up". I know. It's totally not intuitive!

这篇关于SH命令:exec 2 - ;&放大器; 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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