zoukankan      html  css  js  c++  java
  • shell输入输出重定向

    标准输入:0  < , <<或者0< 0<<

    标准输出:1  >,>> 或者1>,1>>

    错误输出:2  2>>,2>

    /dev/null 这个设备,是linux 中黑洞设备,什么信息只要输出给这个设备,都会给吃掉
    将标准输出,错误输出都发送给/dev/null中
    $ ls test.sh test1.sh >/dev/null 2>&1
     
    &,&1代表标准输出
    &2代表错误输出

    //错误输出直接被写在标准输出中,即在终端上屏幕显示。

    :~$ ls -yz 2>&1
    ls: invalid option -- 'y'
    Try 'ls --help' for more information.

    //错误输出会被输出到标准输出,即屏幕显示,而不会写在fname文件中。
    :~$ ls -yz 2>&1 1>fname
    ls: invalid option -- 'y'
    Try 'ls --help' for more information.
    :~$ ls
    AndroidStudioProjects  Desktop    Documents  Downloads  examples.desktop    fname  Music  Pictures    Public    Templates  usr    Videos    work
    :~$ cat fname

    //标准输出会写在fname文件中,错误输出会被输出到标准输出中,即文件fname中。
    :~$ ls -yz 1>fname 2>&1
    :~$ ls
    AndroidStudioProjects  Desktop    Documents  Downloads  examples.desktop    fname  Music  Pictures    Public    Templates  usr    Videos    work
    :~$ cat fname
    ls: invalid option -- 'y'
    Try 'ls --help' for more information.

  • 相关阅读:
    杂记
    asp.net preview 5 bug[转]
    jquery笔记
    北京互联网创业团队诚邀英才加盟
    伊瓜苏大瀑布
    log4net udp组件的应用
    Mock介绍
    自写的BackgroundWorker的学习例子
    RegexBuddy使用例子,及Visual Studio中正则使用的请教
    TestDriven.NET2.14.2190(not RTM) last update at 2008723
  • 原文地址:https://www.cnblogs.com/shamoguzhou/p/6893504.html
Copyright © 2011-2022 走看看