[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
typeset does not make variable local in function
From: |
Clay Harris |
Subject: |
typeset does not make variable local in function |
Date: |
Tue, 5 Jun 2007 22:06:49 -0500 (CDT) |
Problem:
typeset, when used in a function should always mark the variable as local.
When bash is in ksh mode, it fails to do this.
Previous versions did not have this problem, e.g.
GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)
Recent versions of ksh seem to be exhibiting the same bug.
System:
Linux XXX 2.6.20-1.2948.fc6 #1 SMP Fri Apr 27 19:48:40 EDT 2007 i686 i686 i386
GNU/Linux
GNU bash, version 3.1.17(1)-release-(i686-redhat-linux-gnu)
Login shell = /bin/bash
Reproduction:
----------------------------------------------------------------
x1:
#!/bin/bash
F1 () {
typeset T1
T1="Wrong!"
}
echo "Before=$T1"
F1
echo "After=$T1"
----------------------------------------------------------------
----------------------------------------------------------------
x2:
#!/bin/ksh
F1 () {
typeset T1
T1="Wrong!"
}
echo "Before=$T1"
F1
echo "After=$T1"
----------------------------------------------------------------
/bin/bash
./x1
Before=
After=
exit
/bin/bash
./x2
Before=
After=Wrong!
exit
/bin/bash -c ". ./x1"
Before=
After=
/bin/bash -c ". ./x2"
Before=
After=
/bin/ksh -c ". ./x1"
Before=
After=Wrong!
/bin/ksh -c ". ./x2"
Before=
After=Wrong!
- typeset does not make variable local in function,
Clay Harris <=