linux 2>&1

2标准错误
1标准输出
>重定向,默认重定向的内容为标准输出
&等同

举些例子,先建立一个测试文件

vi shtest.sh
#!/bin/sh
echo "aaa"
echoo "bbb"

运行

sh shtest.sh

通常会输出这些

aaa
shtest.sh:line 3: echoo: command not found

其中,aaa 为标准输出,shtest.sh:line 3: echoo: command not found 为标准错误。

2>&1 通俗点说,就是把输出和bug信息这两条管道拧在了一起。

更多的例子
sh shtest.sh > out.txt 等同于sh shtest.sh 1> out.txt 。会在out.txt文件中(若没有,会自动生成)写入aaa,并在控制台打出shtest.sh:line 3: echoo: command not found

sh shtest.sh 2> out.txt,控制台只输出aaa,out.txt文件中写入shtest.sh:line 3: echoo: command not found

sh shtest.sh > out.txt 2>&1,控制台什么都不输出,out.txt文件写入
aaa
shtest.sh:line 3: echoo: command not found

sh shtest.sh 1> out1.txt 2> out2.txt,控制台什么都不输出,out1.txt写入aaa,out2.txt写入shtest.sh:line 3: echoo: command not found

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值