zoukankan      html  css  js  c++  java
  • stdin > 6, and datafile > stdin and process, Finally, 6 > stdin

    #!/bin/bash
    # Redirecting stdin using 'exec'.


    #exec 6<&0          # Link file descriptor #6 with stdin.
                       # Saves stdin.

    exec 0< data-file   # stdin replaced by file "data-file"

    read a1            # Reads first line of file "data-file".
    read a2            # Reads second line of file "data-file."
    read a5

    echo
    echo "Following lines read from file."
    echo "-------------------------------"
    echo $a1
    echo $a2
    echo $a5

    echo; echo; echo

    exec 0<&6 6<&-
    #  Now restore stdin from fd #6, where it had been saved, (0<&6)
    #+ and close fd #6 ( 6<&- ) to free it for other processes to use.
    #
    # <&6 6<&-    also works.

    echo -n "Enter data  "
    read b1  # Now "read" functions as expected, reading from normal stdin.
    echo "Input read from stdin."
    echo "----------------------"
    echo "b1 = $b1"

    echo

    exit 0

  • 相关阅读:
    python 网络客户端编程端口,模块
    Python反转
    ASP.NET的路由系统
    yield 关键字
    C# Lock关键字
    C#中as和is关键字
    13.4 上下文对象
    请求生命周期
    ASP.NET常用的指令
    ASP.NET Page 指令
  • 原文地址:https://www.cnblogs.com/greencolor/p/2073311.html
Copyright © 2011-2022 走看看