shell 交换stderr stdout 3>&1 1>&2 2>&3
来源:互联网 发布:linux if语句使用方法 编辑:程序博客网 时间:2024/05/21 22:39
"command n>file" redirects command's file descriptor n into the given file. The number before the > is the file descriptor bring modified, and what's after the > is what it's being set to write to.
"&m" in place of a file name says to use the current file descriptor m as the destination.
So it's:
- Set file descriptor 3 to a copy of file descriptor 1 (so writing to fd 3 also writes to stdout)
- Set file descriptor 1 to a copy of fd 2 (so writing to fd 1 now writes to stderr)
- Set file descriptor 2 to a copy of fd 3 (so writing to fd 2 now writes to what used to be stdout)
This leaves fd 3 hanging around. Slightly cleaner would be to make that last one "2>&3-", which would close fd 3 as the last step. But it's basically harmless.
参考:
https://www.reddit.com/r/commandline/comments/1gjq6s/bashlinuxconfusion_about_31_12_23_in_script/
阅读全文
0 0
- shell 交换stderr stdout 3>&1 1>&2 2>&3
- C语言I/O学习笔记(1)stdin,stdout和stderr以及重定向
- 重定向stdout & stderr
- stdin,stdout,stderr
- stderr,stdin,stdout
- stdin,stderr,stdout
- stdout和stderr
- stdout, stderr的区别
- stdin,stderr,stdout
- stdin,stdout,stderr转载
- stdin,stdout,stderr详解
- stdin、stdout、stderr
- stdin,stdout,stderr
- stdout 与 stderr 区别
- stdin,stderr,stdout
- Linux stdin stdout stderr
- stdin、stdout和stderr
- stdin, stdout, stderr 详解
- 进程间通讯—消息队列
- Tensorflow学习之逻辑回归的实现
- 数据库锁机制 很详细的教程,易懂
- 数据结构上机3——循环链表
- 英语之介词规则
- shell 交换stderr stdout 3>&1 1>&2 2>&3
- iOS11 [[UIApplication sharedApplication].windows lastObject]
- Java中的值传递和引用传递
- μC/OS实时操作系统简单介绍
- Android开发学习资料
- 《MFC游戏开发》笔记二 建立工程、调整窗口
- Another Keras Tutorial For Neural Network Beginners
- 82. Remove Duplicates from Sorted List II
- Android Fresco gif图