]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/func.tests
8abf4ce03567b670fd818c3363ab21c75833562b
[thirdparty/bash.git] / tests / func.tests
1 a()
2 {
3 x=$((x - 1))
4 return 5
5 }
6
7 b()
8 {
9 x=$((x - 1))
10 a
11 echo a returns $?
12 return 4
13 }
14
15 c()
16 {
17 x=$((x - 1))
18 b
19 echo b returns $?
20 return 3
21 }
22
23 d()
24 {
25 x=$((x - 1))
26 c
27 echo c returns $?
28 return 2
29 }
30
31 e()
32 {
33 d
34 echo d returns $?
35 echo in e
36 x=$((x - 1))
37 return $x
38 }
39
40 f()
41 {
42 e
43 echo e returned $?
44 echo x is $x
45 return 0
46 }
47
48 x=30
49 f
50
51 # make sure unsetting a local variable preserves the `local' attribute
52 f1()
53 {
54 local zz
55 zz=abcde
56 echo $zz
57 unset zz
58 zz=defghi
59 echo $zz
60 }
61
62 zz=ZZ
63 echo $zz
64 f1
65 echo $zz
66
67 unset -f f1
68 f1()
69 {
70 return 5
71 }
72
73 ( f1 )
74 echo $?
75
76 unset -f f1
77 f1()
78 {
79 sleep 5
80 return 5
81 }
82
83 f1 &
84 wait
85 echo $?
86
87 unset -f f1
88
89 f1()
90 {
91 echo $AVAR
92 printenv AVAR
93 }
94
95 AVAR=AVAR
96 echo $AVAR
97 f1
98 AVAR=foo f1
99 echo $AVAR
100
101 unset -f f1
102 # make sure subshells can do a `return' if we're executing in a function
103 f1()
104 {
105 ( return 5 )
106 status=$?
107 echo $status
108 return $status
109 }
110
111 f1
112 echo $?
113
114 declare -F f1 # should print just the name
115 declare -f f1 # should print the definition, too
116
117 # no functions should be exported, right?
118 declare -xF
119 declare -xf