-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.sh
More file actions
executable file
·57 lines (44 loc) · 954 Bytes
/
function.sh
File metadata and controls
executable file
·57 lines (44 loc) · 954 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
49
50
51
52
53
54
55
56
#!/bin/bash
#function test1()
#{
# echo "hello. this is test1 function."
#}
#function test2
#{
# echo "hello. this is test2 function."
#}
#test3()
#{
# echo "hello. this is test3 function"
#}
#echo "start..."
#test1
#test2
#test3
function test1()
{
if [ -z "$1" ]; then
echo "param1 is missing"
fi
if [ -z "$2" ]; then
echo "param2 is missing"
fi
# local keyword를 사용하면, 함수안에서만 사용된다.
# local keyword는 함수에서만 사용할 수 있다.
local target="${1}"
local action="${2}"
echo "this is test1"
echo "first param is ${target}"
echo "second param is ${action}"
return 0
# return 은 0~255 까지만 가능.
# return "aaaaa" 하면 error 숫자를 return 해야 함..
}
# parameter를 넘겨준다.
result=$(test1 "Hello" "world") # echo의 출력문을 결과값으로 받을 수 있다.
if [ "$result" -eq 0 ]; then
echo "sucess"
else
echo "fail"
fi
echo "test1 returns \"$result\""