1 |
|
2 | #### Incomplete Function
|
3 | ## code: foo()
|
4 | ## status: 2
|
5 | ## BUG mksh status: 0
|
6 |
|
7 | #### Incomplete Function 2
|
8 | ## code: foo() {
|
9 | ## status: 2
|
10 | ## OK mksh status: 1
|
11 |
|
12 | #### Bad function
|
13 | ## code: foo(ls)
|
14 | ## status: 2
|
15 | ## OK mksh status: 1
|
16 |
|
17 | #### Unbraced function body.
|
18 | # dash allows this, but bash does not. The POSIX grammar might not allow
|
19 | # this? Because a function body needs a compound command.
|
20 | # function_body : compound_command
|
21 | # | compound_command redirect_list /* Apply rule 9 */
|
22 | ## code: one_line() ls; one_line;
|
23 | ## status: 0
|
24 | ## OK bash/osh status: 2
|
25 |
|
26 | #### Function with spaces, to see if ( and ) are separate tokens.
|
27 | # NOTE: Newline after ( is not OK.
|
28 | fun ( ) { echo in-func; }; fun
|
29 | ## stdout: in-func
|
30 |
|
31 | #### subshell function
|
32 | # bash allows this.
|
33 | i=0
|
34 | j=0
|
35 | inc() { i=$((i+5)); }
|
36 | inc_subshell() ( j=$((j+5)); )
|
37 | inc
|
38 | inc_subshell
|
39 | echo $i $j
|
40 | ## stdout: 5 0
|
41 |
|
42 | #### Hard case, function with } token in it
|
43 | rbrace() { echo }; }; rbrace
|
44 | ## stdout: }
|
45 |
|
46 | #### . in function name
|
47 | # bash accepts; dash doesn't
|
48 | func-name.ext ( ) { echo func-name.ext; }
|
49 | func-name.ext
|
50 | ## stdout: func-name.ext
|
51 | ## OK dash status: 2
|
52 | ## OK dash stdout-json: ""
|
53 |
|
54 | #### = in function name
|
55 | # WOW, bash is so lenient. foo=bar is a command, I suppose. I think I'm doing
|
56 | # to disallow this one.
|
57 | func-name=ext ( ) { echo func-name=ext; }
|
58 | func-name=ext
|
59 | ## stdout: func-name=ext
|
60 | ## OK dash status: 2
|
61 | ## OK dash stdout-json: ""
|
62 | ## OK mksh status: 1
|
63 | ## OK mksh stdout-json: ""
|
64 |
|
65 | #### Function name with $
|
66 | $foo-bar() { ls ; }
|
67 | ## status: 2
|
68 | ## OK bash/mksh status: 1
|
69 |
|
70 | #### Function name with command sub
|
71 | foo-$(echo hi)() { ls ; }
|
72 | ## status: 2
|
73 | ## OK bash/mksh status: 1
|
74 |
|
75 | #### Function name with !
|
76 | # bash allows this; dash doesn't.
|
77 | foo!bar() { ls ; }
|
78 | ## status: 0
|
79 | ## OK dash status: 2
|
80 |
|
81 | #### Function name with -
|
82 | # bash allows this; dash doesn't.
|
83 | foo-bar() { ls ; }
|
84 | ## status: 0
|
85 | ## OK dash status: 2
|
86 |
|
87 | #### Break after ) is OK.
|
88 | # newline is always a token in "normal" state.
|
89 | echo hi; fun ( )
|
90 | { echo in-func; }
|
91 | fun
|
92 | ## STDOUT:
|
93 | hi
|
94 | in-func
|
95 | ## END
|
96 |
|
97 | #### Nested definition
|
98 | # A function definition is a command, so it can be nested
|
99 | fun() {
|
100 | nested_func() { echo nested; }
|
101 | nested_func
|
102 | }
|
103 | fun
|
104 | ## stdout: nested
|
105 |
|