zoukankan      html  css  js  c++  java
  • Redirecting stdout using exec

    #!/bin/bash
    # reassign-stdout.sh

    LOGFILE=logfile.txt

    exec 6>&1           # Link file descriptor #6 with stdout.
                        # Saves stdout.

    exec > $LOGFILE     # stdout replaced with file "logfile.txt".

    # ----------------------------------------------------------- #
    # All output from commands in this block sent to file $LOGFILE.

    echo -n "Logfile: "
    date
    echo "-------------------------------------"
    echo

    echo "Output of \"ls -al\" command"
    echo
    ls -al
    echo; echo
    echo "Output of \"df\" command"
    echo
    df

    # ----------------------------------------------------------- #

    exec 1>&6 6>&-      # Restore stdout and close file descriptor #6.

    echo
    echo "== stdout now restored to default == "
    echo
    ls -al
    echo

    exit 0

  • 相关阅读:
    gulp基础
    字符串及字符串的方法
    ES5
    JS的设计模式
    VSN与GitHub
    JS闭包函数的概念及函数的继承
    Promise的工作原理
    JS原生的Ajax
    MySQL数据库的基本操作
    & 异步使用场景
  • 原文地址:https://www.cnblogs.com/greencolor/p/2073323.html
Copyright © 2011-2022 走看看