]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/func3.sub
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / func3.sub
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 #
14 #
15 # test some posix-mode-specific function behavior
16 #
17 set -o posix
18 func()
19 {
20 return 5
21 }
22
23 myfunction () {
24 var=20 return
25 }
26 var=10
27 echo expect 5 10
28 func
29 echo $? $var
30
31 myfunction
32 echo expect 20
33 echo $var
34
35 echo expect 5 20
36 func
37 echo $? $var
38
39 echo expect 5 20
40 var=30 func
41 echo $? $var
42
43 : ${TMPDIR:=/tmp}
44 TMPFILE=$TMPDIR/func3.sub.$$
45
46 rm -f $TMPFILE
47 echo 'var=40 return 2' > $TMPFILE
48
49 # test the behavior of `return' and preceding variable assignments here
50 # because it's convenient
51 var=10
52 echo expect 2 40
53 . $TMPFILE
54 echo $? $var
55
56 rm -f $TMPFILE
57
58 #set -o posix
59 var=0
60 func()
61 {
62 var=20 return 5
63 }
64
65 echo expect 5 20
66 var=30 func
67 echo $? $var