Linux

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/u014284252/article/details/51784217
         <!--一个博主专栏付费入口结束-->
        <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-d284373521.css">
                                    <div id="content_views" class="markdown_views">
                <!-- flowchart 箭头图标 勿删 -->
                <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                    <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                </svg>
                                        <pre class="prettyprint" name="code"><code class="hljs perl has-numbering" onclick="mdcp.copyCode(event)" style="position: unset;">linux &amp;&gt; 与 &gt;的区别(也可以说成是linux stdout(标准输出) stderr(标准错误)的区别)

&>可以将stderr错误信息重定向输出

>可以将stdout标准输出信息重定向输出

下面是实际在linux命令行的测试结果:
[root@Dev_yang shellScript]# lll
-bash: lll: command not found //由于Linux没有lll这个命令所以会显示错误信息,这个就是stderr输出的错误信息
[root@Dev_yang shellScript]# lll>test
-bash: lll: command not found //由于这个是错误信息 所以不能使用标准输出>将信息重定向到test文件中,所以错误信息直接在控制台打印出来了
[root@Dev_yang shellScript]# lll&>test //使用&>重定向 错误信息没有输出到控制台了,表示错误信息正确重定向到了test文件
[root@Dev_yang shellScript]# cat test
-bash: lll: command not found //通过cat命令确实看到了 保存的错误信息

总结:>只能将正常信息重定向
&>可以将错误信息或者普通信息都重定向输出(下面是实测)

[root@Dev_yang shellScript]# cat test

[root@Dev_yang shellScript]# ll&>test
[root@Dev_yang shellScript]# cat test
total 8
-rwxr-xr-x 1 root root 79 Jun 29 04:14 script.sh
-rw-r–r-- 1 root root 0 Jun 29 04:52 test
-rw-r–r-- 1 root root 2444 Jun 23 2014 vpn_centos6.sh
[root@Dev_yang shellScript]# echo “” >test
[root@Dev_yang shellScript]# cat test

[root@Dev_yang shellScript]# ll>test
[root@Dev_yang shellScript]# cat te
cat: te: No such file or directory
[root@Dev_yang shellScript]# cat test
total 8
-rwxr-xr-x 1 root root 79 Jun 29 04:14 script.sh
-rw-r–r-- 1 root root 0 Jun 29 04:53 test
-rw-r–r-- 1 root root 2444 Jun 23 2014 vpn_centos6.sh
[root@Dev_yang shellScript]#

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值