aboutsummaryrefslogtreecommitdiff
blob: 53cc6da90a440212489b784a95a5646b0221960a (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
EAPI=3

src_unpack() {
	EAPI=$((EAPI+1))
}

src_unpack
src_unpack

MY_PV=2.0.3-r1

nested_func_with_args() {
	ARG6=$1
	ARG7=$3
}

func_with_args() {
	ARG1=$1
	ARG2=$2
	ARG3=$3
	ARG4=$4
	ARG5=$5
	nested_func_with_args $4
}
FOO001="4		5"
ARRAY=(1 2 3)
func_with_args ${ARRAY[@]} $FOO001
func_with_args 100 $ARG2 $ARG3 $ARG4

func-with-return()
{
    return 1
    NOT_EXIST=1
}
func-with-return
RETURN_STATUS=$?
func_with-return2()
{
    true
    return
    NOT_EXIST=1
}
func_with-return2
RETURN_STATUS2=$?

func_nested1() {
    echo $foo_nested ${bar_nested[0]} $localbar
}
func_nested2() {
    local foo_nested=hi bar_nested=(1 2 3) localbar
    localbar=1
    echo ${bar_nested[@]}
    echo ${not_exist[@]}
    echo ${#bar_nested[@]}
    echo ${#non_exist[@]}
    echo ${#foo_nested}
    echo ${#non_exist}
    echo ${foo_nested:-wrong}
    echo ${non_exist:-right}
    func_nested1
}
func_nested2
echo $localbar

let() {
    echo "overloaded let"
}
let "1 + 2"
func_positional_args() {
    IFS="abc" echo "$*"
    IFS="abc" echo $*
    IFS=abc
    echo "$*"
    echo $*
}
func_positional_args 1 2 3
IFS=" \t\n"

nested_func_override_positional_args() {
  echo $@
  set -- 40 50 60
  echo $@
}
func_override_positional_args() {
  echo $@
  nested_func_override_positional_args 4 5 6
  set -- 10 20 30
  echo $@
}
set -- foo bar
func_override_positional_args 1 2 3
echo $@

if true; then
    function_in_compound_statement() {
        echo "function_in_compound_statement"
    }
fi
if false; then
    function_in_compound_statement() {
        echo "I should not get called"
    }
fi
function_in_compound_statement

function shift_test() {
    shift
    echo $1
}

shift_test 1 2
test-flag-CC() {
    function="$1"
    echo "'${function}' function is not defined"
    echo "CC" "$1";
}
test-flag-CC abc