<!--一个博主专栏付费入口结束-->
<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 &> 与 >的区别(也可以说成是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