-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_function.bash
More file actions
48 lines (39 loc) · 766 Bytes
/
10_function.bash
File metadata and controls
48 lines (39 loc) · 766 Bytes
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
#!/usr/bin/env bash
# # Function must be defined before we can use it
my_func () {
echo "Hello, it's $USER, this is my 1st bash function! This function name is $FUNCNAME"
}
my_func
# Function parameters
greeting () {
local foo="Foooo" # Local variables are only available in the function
bar="Bazzz"
if [[ $1 ]]; then
echo "Hello, $1"
else
echo "Hello, the unknown!"
fi
return 0
}
greeting "John"
greeting
echo "foo is: $foo"
echo "baz is: $bar"
### Challenge
print() {
[[ $1 -ge $2 ]] && return
i=$1
if [[ $(($i % 2)) == 0 ]]; then
indent=$(($3 + 1))
for ((j = 0; j < $indent; j++)); do
echo -n " "
done
echo "$i"
fi
print $(($i + 1)) $2 indent
}
main() {
echo $FUNCNAME
print $1 $2 0
}
main $1 $2