linux shell 重定向中的 & 符号

写一个简单的 demo 示例

#include <stdio.h>

int main()
{
    fprintf(stdout, "stdout output\n");
    fprintf(stderr, "stderr output\n");
       
    return 0;
}

$gcc test.c -o test

$./test > /dev/null

stderr output

$./test > /dev/null 2>&1

$

对于重定向符号,可以这么理解,简单的

command > /dev/null

此时 > 的前边是省略了 1(标准输出) 的。

2 > &1

意思是将 2(标准错误) 中的数据也重定向到 1(标准输出) 中。

猜你喜欢

转载自www.cnblogs.com/rivsidn/p/10418416.html