This is the mail archive of the
cygwin
mailing list for the Cygwin project.
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
- Date: Mon, 24 Mar 2014 19:02:13 +0100
- Subject: Advanced Bash-Scripting Guide script result different with it on the linux
- Authentication-results: sourceware.org; auth=none
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