zoukankan      html  css  js  c++  java
  • shell脚本使用技巧2

    0--stdin标准输入

    1--stdout标准输出

    2--stderr标准错误

    重定向

    echo "this is a good idea " > temp.txt

    temp.txt内容会被首先清空后再输入“this is a good idea”

    追加

    echo "this is a bad idea " >> temp.txt

    cat temp.txt

    打印退出状态:echo $?

    ls + 2>out.txt

    2输入错误时候,输出到out.txt

    cmd 2>stderr.txt 1>stdout.txt

    正确输出到stdout.txt,错误输出到stderr.txt中;

    重定向到同一个文件:

    cmd 2>&1 output.txt

    tee

    打印stdout,并重向到一个文件中:tee

    command | tee file1

    cat a* | tee -a out.txt | cat -n

    -a 会覆盖文件,-n给文件加数字号

    将脚本内部的文本块进行重定向

    #!/bin/bash

    cat<<EOF>log.txt

    LOG FILE HEADER

    this is a test log file

    Function:system staticstics

    EOF

    怕什么真理无穷,进一寸有一寸的欢喜。---胡适
  • 相关阅读:
    python二维数组切片
    [转载]MIPS常用指令及实例
    使用vim编程步骤
    数组指针和指针数组
    线程基础
    顶层const和底层const
    递归调用
    输出流
    C++代码规范
    I/O流
  • 原文地址:https://www.cnblogs.com/hujianglang/p/6965375.html
Copyright © 2011-2022 走看看