summaryrefslogtreecommitdiff
path: root/tests/func.tests
blob: 8abf4ce03567b670fd818c3363ab21c75833562b (plain)
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
a()
{
	x=$((x - 1))
	return 5
}

b()
{
	x=$((x - 1))
	a
	echo a returns $?
	return 4
}

c()
{
	x=$((x - 1))
	b
	echo b returns $?
	return 3
}

d()
{
	x=$((x - 1))
	c
	echo c returns $?
	return 2
}

e()
{
	d
	echo d returns $?
	echo in e
	x=$((x - 1))
	return $x
}

f()
{
	e
	echo e returned $?
	echo x is $x
	return 0
}

x=30
f

# make sure unsetting a local variable preserves the `local' attribute
f1()
{
	local zz
	zz=abcde
	echo $zz
	unset zz
	zz=defghi
	echo $zz
}

zz=ZZ
echo $zz
f1
echo $zz

unset -f f1
f1()
{
	return 5
}

( f1 )
echo $?

unset -f f1
f1()
{
	sleep 5
	return 5
}

f1 &
wait
echo $?

unset -f f1

f1()
{
	echo $AVAR
	printenv AVAR
}

AVAR=AVAR
echo $AVAR
f1
AVAR=foo f1
echo $AVAR

unset -f f1
# make sure subshells can do a `return' if we're executing in a function
f1()
{
	( return 5 )
	status=$?
	echo $status
	return $status
}

f1
echo $?

declare -F f1	# should print just the name
declare -f f1	# should print the definition, too

# no functions should be exported, right?
declare -xF
declare -xf