-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.sh
More file actions
executable file
·50 lines (38 loc) · 1.11 KB
/
function.sh
File metadata and controls
executable file
·50 lines (38 loc) · 1.11 KB
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
#!/bin/bash
Hello(){
echo "Url is http://see.sidian.edu.cn/cpp/shell/"
}
# Invoke your function
Hello
funWithReturn(){
echo "The function is to get the sum of two numbers..."
echo -n "Input first numbers:"
read aNum
echo -n "Input another numbers:"
read anotherNum
echo "The two numbers are $aNum and $anotherNum !"
return $(($aNum+$anotherNum))
}
funWithReturn
# Capture value returned by last command
ret=$?
echo "The sum of two numbers is $ret !"
# calling one function from another
number_one(){
echo "Url_1 is http://see.xidian.edu.cn/cpp/shell/"
number_two
}
number_two(){
echo "Url_2 is http://see.xidian.edu.cn/cpp/u/xitong/"
}
number_one
funWithParam(){
echo "The value of the first parameter is $1 !"
echo "The value of the second parameter is $2 !"
echo "The value of the tenth parameter is $10 !"
echo "The value of the tenth parameter is ${10} !"
echo "The value of the eleventh parameter is ${11} !"
echo "The amount of the parameters is $# !" # 参数个数
echo "The string of the parameters is $* !" # 传递给函数的所有参数
}
funWithParam 1 2 3 4 5 6 7 8 9 34 73