www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/03/24/14:02:49

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:date:message-id:subject:from:to
:content-type; q=dns; s=default; b=hwQb2GysMhb2bFcYUzxFIr2mCfvdv
QIy5HwJ6uKevuvq3Xq05znyUwbYe9VF9MrsCCdqSv2+IJjfID1Anuxv6ESzVp7F4
FPn+lfGNbB2HZsU6H2ZwUD6Zfbvd9L48pGmEnS7CHRR9p5NCzsKZRMijObmmxyym
Z3isU9YwmjyrAw=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:date:message-id:subject:from:to
:content-type; s=default; bh=I04y1kOyvBevoDt4Vi33Irml6ag=; b=h7X
RzYjjMoUGwhOd2az8FRlZGU7ebTNMCxdgaiqNxyjSI/RsB7fLoo6KrGyIVhUQ5Lr
SKGYViSQK3oVc/VGS3Q0Z8TSygfTOgfOxsnUV7aB4Jg2eR4hOG1AY1IXLSWNf0aR
mnv4rdL0vKitAzHwwr2Eg2Mz3EXchlFBpk7wmBN8=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_40,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-wi0-f180.google.com
MIME-Version: 1.0
X-Received: by 10.181.11.169 with SMTP id ej9mr17789591wid.18.1395684133453; Mon, 24 Mar 2014 11:02:13 -0700 (PDT)
Date: Mon, 24 Mar 2014 19:02:13 +0100
Message-ID: <CAE5KSAYaBGnn_ifz67wHb7Li4Q8pJ=s=cHshbjjyj1ufvHW1mg@mail.gmail.com>
Subject: Advanced Bash-Scripting Guide script result different with it on the linux
From: shu <shu DOT eclipse AT gmail DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes

 A script  in Advanced Bash-Scripting Guide (at the bottom of
http://www.tldp.org/LDP/abs/html/ioredirintro.html )

Even i had change "sleep 1" -->"sleep 3" , still different.
Come out result:
2nd, to stderr
FD4: FIFO2: 3rd, to fd 3
FD6: FIFO2: 3rd, to fd 3
FD5: FIFO2: 3rd, to fd 3
FIFO1: FIFO2: 3rd, to fd 3
FD4: 4th, to fd 4
FD5: 5th, to fd 5
FD5: PIPE: 6th, through a pipe, to fd 5
FD6: 7th, to fd 6
FIFO1: 8th, to fd 7
FIFO1: FD8: 9th, to fd 8, to fd7


While linux result is:
1st, to stdout
2nd, to stderr
FIFO2: 3rd, to fd 3
FD4: FIFO2: 3rd, to fd 3
FIFO1: FIFO2: 3rd, to fd 3
FD5: FIFO2: 3rd, to fd 3
FD6: FIFO2: 3rd, to fd 3
FD4: 4th, to fd 4
FD5: 5th, to fd 5
FD5: PIPE: 6th, through a pipe, to fd 5
FD6: 7th, to fd 6
FIFO1: 8th, to fd 7
FIFO1: FD8: 9th, to fd 8, to fd7



#! /usr/bin/env bash

mkfifo /tmp/fifo1 /tmp/fifo2
while read a; do echo "FIFO1: $a"; done < /tmp/fifo1 & exec 7> /tmp/fifo1
exec 8> >(while read a; do echo "FD8: $a, to fd7"; done >&7)

exec 3>&1
(
 (
  (
   while read a; do echo "FIFO2: $a"; done < /tmp/fifo2 | tee /dev/stderr \
   | tee /dev/fd/4 | tee /dev/fd/5 | tee /dev/fd/6 >&7 & exec 3> /tmp/fifo2

   echo 1st, to stdout
   sleep 1
   echo 2nd, to stderr >&2
   sleep 1
   echo 3rd, to fd 3 >&3
   sleep 1
   echo 4th, to fd 4 >&4
   sleep 1
   echo 5th, to fd 5 >&5
   sleep 1
   echo 6th, through a pipe | sed 's/.*/PIPE: &, to fd 5/' >&5
   sleep 1
   echo 7th, to fd 6 >&6
   sleep 1
   echo 8th, to fd 7 >&7
   sleep 1
   echo 9th, to fd 8 >&8

  ) 4>&1 >&3 3>&- | while read a; do echo "FD4: $a"; done 1>&3 5>&- 6>&-
 ) 5>&1 >&3 | while read a; do echo "FD5: $a"; done 1>&3 6>&-
) 6>&1 >&3 | while read a; do echo "FD6: $a"; done 3>&-

rm -f /tmp/fifo1 /tmp/fifo2


# For each command and subshell, figure out which fd points to what.
# Good luck!

exit 0

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019