linux标准输出 1<&2,linux bash关闭标准输出1(exec 1<&-)后重新打开

标签:

linux bash shell的再次学习。

文件描述符:

stdin,stdout 和 stderr 的文件描述符分别是 0,1 和 2(一个文件描述符说白了就是文件系统为了跟踪这个打开的文件而分配给它的一个数字)

这样子来读入文件fly的内容

bb04d2d5f6c80ea0767681bb1056793d.png

清空文件

2322565dbdc45dee9952c9ca6f8f74c4.png

----------------------------------------------------------------------------

I am running this on an Ubuntu machine, so I am not sure if it'll work for you, but this is what I did:

$ exec 1>&0

$ exec 2>&0

Suddenly, I had STDOUT and STDERR reconnected. Magic!

Explanation: Running the following commands, we get the following output:

$ ls -l /dev/stdout

lrwxrwxrwx 1 root root 15 Jun 11 23:39 /dev/stdout -> /proc/self/fd/1

$ ls -l /proc/self/fd/1

lrwx------ 1 jay jay 64 Jun 22 01:34 /proc/self/fd/1 -> /dev/pts/10

$ ls -l /proc/self/fd/

total 0

lrwx------ 1 jay jay 64 Jun 22 01:35 0 -> /dev/pts/10

lrwx------ 1 jay jay 64 Jun 22 01:35 1 -> /dev/pts/10

lrwx------ 1 jay jay 64 Jun 22 01:35 2 -> /dev/pts/10

lr-x------ 1 jay jay 64 Jun 22 01:35 3 -> /proc/12224/fd

Since all three fd's point to the same thing, we can return them back to normal just by pointing to /dev/pts/10 which the exec 1>&0 and exec 2>&0 do

标签:

来源: https://www.cnblogs.com/oxspirt/p/10249562.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值