Redirection of *while* in sh

Redirection of *while* in sh

Post by Peter » Wed, 20 Nov 1991 09:40:21



Hi,
        I have just discovered a peculiar behaviour due to redirection
of input of the while command in sh (for sun3,4 running sunos4.1.1).

sample script:
$ cat s1
#!/bin/sh
a="a"
while read c; do a="$a $c"; done
echo $a
$ s1
b c d
e f g
a b c d e f g           <--- (i)
$ cat s2
#!/bin/sh
a="a"
while read c; do a="$a $c"; done < tt
echo $a
$ cat tt
b c d
e f g
$ s2
a                       <--- (ii)

        Therefore (i) and (ii) are not the same.  It seems like the
do .. done in the second case is done in a subshell(?), whereas it isn't
in the first case.
        I have also tried these examples using bash (a GNU ksh clone),
and it gives same result in both cases (the result is as in case (i)).

        I don't know whether this is peculiarity specific to sun, or
is more general, but any help would be much appreciated,

                        Pete.

 
 
 

1. Circular redirection in sh

I have written a program (in c) which is to drive a communication session using
cu under unix.  The program is intended to take as its stdin the stdout from
cu, and its stdout is intended to go to the stdin of cu.  Both of these
programs should be spawned as a subproccess of a third program using the c
system call.

So I can have system ("a.out | cu");
I can also have system ("cu | a.out");
but I don't know how to redirect the outputs both ways as in:

            a.out --->  cu
              ^         |
              |         |
               ---------

if you take my meaning.

Any suggestions?

--

PP-ASEL  -  Tandem Flybaby Builder  -  EAA-284 (Waynesville, OH)
Those who beat their swords into plowshares will plow for those who do not.

2. What to do when making world...

3. redirection vs. pipes in /bin/sh?

4. I am being HACKED!! I need security info.

5. /bin/sh redirection of stdin, stderr woes

6. Question about Linux and Viper II Z200

7. Execute a sh script under perl and sh: sh script; perl script?

8. find and multiple commands

9. A question about the time program & redirection in sh

10. sh/ksh redirection 1> outfile 2>&1

11. sh I/O redirection

12. strange behaviour with error redirection in 'sh' on solaris 8

13. error redirection in sh (possible flame receptacle?)