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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
# unset-p.tst: test of the unset built-in for any POSIX-compliant shell
posix="true"
echo echo external a > a
echo echo external b > b
echo echo external c > c
echo echo external d > d
echo echo external x > x
chmod a+x a b c d x
setup 'PATH=.:$PATH'
test_oE -e 0 'deleting existing variable (default)' -e
a=1 b=2
unset a
echo ${a-unset} ${b-unset}
__IN__
unset 2
__OUT__
test_oE -e 0 'deleting non-existing variable (default)' -e
a=1 b=2
unset x
echo ${a-unset} ${b-unset} ${x-unset}
__IN__
1 2 unset
__OUT__
test_oE -e 0 'deleting many variables (default)' -e
a=1 b=2 c=3 d=4
unset a b x c
echo ${a-unset} ${b-unset} ${c-unset} ${d-unset} ${x-unset}
__IN__
unset unset unset 4 unset
__OUT__
test_oE -e 0 'only variable is deleted by default' -e
a() { echo "$@"; }
a=1
unset a
a ${a-unset}
__IN__
unset
__OUT__
test_oE -e 0 'deleting many variables (-v)' -e
a=1 b=2 c=3 d=4
unset -v a b x c
echo ${a-unset} ${b-unset} ${c-unset} ${d-unset} ${x-unset}
__IN__
unset unset unset 4 unset
__OUT__
test_oE -e 0 'only variable is deleted (-v)' -e
a() { echo "$@"; }
a=1
unset -v a
a ${a-unset}
__IN__
unset
__OUT__
test_oE -e 0 'deleting existing function (-f)' -e
a() { echo a; }
b() { echo b; }
unset -f b
a
b
__IN__
a
external b
__OUT__
test_oE -e 0 'deleting non-existing function (-f)' -e
a() { echo a; }
unset -f b
a
b
__IN__
a
external b
__OUT__
test_oE -e 0 'deleting many functions (-f)' -e
a() { echo a; }
b() { echo b; }
c() { echo c; }
d() { echo d; }
unset -f a b x c
a
b
c
d
x
__IN__
external a
external b
external c
d
external x
__OUT__
test_oE -e 0 'only function is deleted (-f)' -e
a=1
a() { echo a; }
unset -f a
echo ${a-unset}
__IN__
1
__OUT__
test_O -d -e n 'read-only variable cannot be deleted (default)'
readonly a=
unset a
echo not reached # special built-in error kills non-interactive shell
__IN__
test_O -d -e n 'read-only variable cannot be deleted (-v)'
readonly a=
unset -v a
echo not reached # special built-in error kills non-interactive shell
__IN__
# vim: set ft=sh ts=8 sts=4 sw=4 et:
|