Changes between Version 5 and Version 6 of jazz/10-05-30


Ignore:
Timestamp:
May 30, 2010, 11:46:55 PM (14 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • jazz/10-05-30

    v5 v6  
    3535sun-java6-jre   sun-java6-jre/stopthread        select  true
    3636}}}
     37
     38== Shell Script ==
     39
     40 * 如何在 shell script 裡面把標準輸入跟標準輸出重新導向到另一個路徑呢?!
     41   * [參考] [http://www.linuxquestions.org/questions/linux-general-1/shell-scripting-how-to-redirect-output-from-within-the-script-itself-446558/ Shell scripting: How to redirect output from within the script itself? ]
     42{{{
     43#!sh
     44#! /bin/bash
     45
     46TARGET="target-file"
     47
     48# file descriptor 4 prints to STDOUT and to TARGET
     49exec 4> >(while read a; do echo $a; echo $a >>$TARGET; done)
     50# file descriptor 5 remembers STDOUT
     51exec 5>&1
     52
     53# now STDOUT is redirected
     54exec >&4
     55date
     56
     57# wer're done
     58exec >&5
     59echo "Date sent to fd4."
     60}}}