|
From: | Morard Jean-Louis |
Subject: | Sub shell mit pipes |
Date: | Wed, 11 Aug 2004 09:59:11 +0200 |
Dear all,
I think there is a problem whith the bash shell, at least in the version 2.05b on RedHat EL 3. Here is my script (just a test for demonstration purposes):
#!/bin/bash
ALL=""
cat /tmp/text | while read LINE
do
ALL="$LINE $ALL"
echo $ALL
done
echo "ALL = $ALL"
The output is the following:
a
b a
c b a
d c b a
e d c b a
f e d c b a
g f e d c b a
ALL =
The behaviour could be considered as correct if we think about sub shells and so on... But it causes problems with portability from a standard ksh script on solaris. And it's not quite nice if we think that the following works correctly:
#!/bin/bash
ALL=""
cat /tmp/text | while read LINE
do
ALL="$LINE $ALL"
echo $ALL
done < /tmp/text
echo "ALL = $ALL"
The output is the following:
a
b a
c b a
d c b a
e d c b a
f e d c b a
g f e d c b a
ALL = g f e d c b a
Is there any environment variable to set so that it works correctly?
Thanks for your help!
Jean-Louis
______________________________________________________
Jean-Louis Morard
Systemspezialist
Tel: 031-666.14.31
Email: Jean-Louis.Morard@rtc.ch
Real-Time Center AG
Schwarzenburgstrasse 160
3097 Liebefeld
Schweiz
Postadresse:
Postfach
3001 Bern
Schweiz
Telefon +41 (0)31 666 16 00
Fax +41 (0)31 666 16 14
Internet: http://www.rtc.ch
______________________________________________________
[Prev in Thread] | Current Thread | [Next in Thread] |