]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/func3.sub
bash-5.1-alpha release
[thirdparty/bash.git] / tests / func3.sub
CommitLineData
712f80b0
CR
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation, either version 3 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program. If not, see <http://www.gnu.org/licenses/>.
13#
28ef6c31
JA
14#
15# test some posix-mode-specific function behavior
16#
17set -o posix
18func()
19{
20 return 5
21}
22
23myfunction () {
24 var=20 return
25}
26var=10
27echo expect 5 10
28func
29echo $? $var
30
31myfunction
32echo expect 20
33echo $var
34
35echo expect 5 20
36func
37echo $? $var
38
712f80b0 39echo expect 5 20
28ef6c31
JA
40var=30 func
41echo $? $var
42
43: ${TMPDIR:=/tmp}
44TMPFILE=$TMPDIR/func3.sub.$$
45
46rm -f $TMPFILE
47echo 'var=40 return 2' > $TMPFILE
48
49# test the behavior of `return' and preceding variable assignments here
50# because it's convenient
51var=10
52echo expect 2 40
53. $TMPFILE
54echo $? $var
55
56rm -f $TMPFILE
57
58#set -o posix
59var=0
60func()
61{
62 var=20 return 5
63}
64
65echo expect 5 20
66var=30 func
67echo $? $var