bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Logically equivalent statements output different results. Suspect probl


From: Kalidas Yeturu
Subject: Logically equivalent statements output different results. Suspect problem with 'pipe'.
Date: Tue, 2 Mar 2010 15:41:36 +0530

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  -D_GNU_SOURCE  -O2
-g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic
uname output: Linux adenine.physics.iisc.ernet.in 2.6.21-1.3194.fc7 #1 SMP
Wed May 23 22:47:07 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 3.2
Patch Level: 33
Release Status: release

Description:
    [Detailed description of the problem, suggestion, or complaint.]

Logically equivalent statements output different results. Suspect problem
with 'pipe'.


Let there be two files - a and b.

#---number of lines in a is 2---
echo "0
0" > a

#---number of lines in b is 3---
echo "0
0
0" > b;

p=0; for lig in `cat a`; do for i in `cat b`; do echo "printing $p";
((p=$p+1)); done; done

#outputs
printing 0
printing 1
printing 2
printing 3
printing 4
printing 5


p=0; for lig in `cat a`; do cat b | while read i; do echo "printing $p";
((p=$p+1)); done; done

#outputs        (I DO NOT EXPECT p TO BE RESET EACH TIME WHILE RUNS)
printing 0
printing 1
printing 2
printing 0
printing 1
printing 2

Repeat-By:
    [Describe the sequence of events that causes the problem
    to occur.]

Above statements can be executed in terminal for reproduction of the
problem.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]