[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
while do done has problems with global variables
From: |
Joern . Rink |
Subject: |
while do done has problems with global variables |
Date: |
Tue, 27 Jun 2006 16:36:30 +0200 |
Configuration Information [Automatically generated, do not change]:
Machine: s390
OS: linux
Compiler: gcc -I/usr/src/packages/BUILD/bash-2.05b
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='s390'
-DCONF_OSTYPE='linux' -DCONF_MACHTYPE='s390-ibm-linux' -DCONF_VENDOR='ibm'
-DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -O2 -fsigned-char
-D_GNU_SOURCE -Wall -pipe -g
uname output: Linux LXPTIV01 2.4.21-292-default #1 SMP Wed May 25 13:26:41
UTC 2005 s390 unknown
Machine Type: s390-ibm-linux
Bash Version: 2.05b
Patch Level: 0
Release Status: release
Description:
[#!/bin/bash
I=5
function F_Muster
{
ls -1 | while read f; do
let I=I+1
export I
echo "I is $I"
done
echo "I after loop: $I"
((I=I+10))
return 0
}
F_Muster
echo "========: $I"
exit 0
produces:
[xgadrin@mobile bash]$ ./bash_p.sh
I is 6
I after loop: 5
========: 15
That means, in the loop we can work with the global Variable I, but not
after the loop, I is reset to 5.
We have tested this on bash on fedora, aix linux-s390.
On ksh the script works as expected.
]
Repeat-By:
[Describe the sequence of events that causes the problem
to occur.]
Fix:
[Description of how to fix the problem. If you don't know a
fix for the problem, don't include this section.]
Mit freundlichen Grüßen
Jörn Rink
Produktion / Basis und Infrastruktur
Tel.: 0251 7133 - 1410 - Fax.: 0251 7133 - 91410
eMail: Joern.Rink@gad.de
GAD eG
Weseler Straße 500 - 48163 Münster
http://www.gad.de
- while do done has problems with global variables,
Joern . Rink <=