1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# set of tests for posix interp 1009, unset variable in tempenv
# posix doesn't have local variables, but other shells echo
#
# local local global global
#
# ash-based shells unset local x in f1 after call to f2; we can do this
# with localvar_unset option
f1()
{
local x=local
echo $FUNCNAME: x = $x
f2
echo after f2: x = ${x-unset}
}
f2()
{
echo $FUNCNAME: x = $x
unset x
}
x=global
f1
echo default after f1: x = $x
shopt -s localvar_unset
x=global
f1
echo localvar_unset after f1: x = $x
shopt -u localvar_unset
unset -f f1 f2
unset -v x
# posix says this should echo temp, then global
f1()
{
echo $FUNCNAME: x = $x
unset x
}
x=global
x=temp f1
echo after f1: x = $x
unset -f f1
unset -v x
# posix says this should echo 'unset'
# interp 1009
x=global
x=temp unset x
echo 1009: after bash unset: x = ${x-unset}
set -o posix
x=global
x=temp unset x
echo 1009: after posix unset: x = ${x-unset}
set +o posix
unset -v x
# posix says this should echo local, unset, global
f1()
{
local x=local
echo $FUNCNAME: x = $x
x=temp unset x
echo after unset $FUNCNAME: x = ${x-unset}
}
x=global
f1
echo 1009: after bash f1: x = $x
set -o posix
x=global
f1
echo 1009: after posix f1: x = $x
set +o posix
unset -f f1
unset -v x
|