[root@allen shell]# cat fun.sh
#!/bin/bash
function inp(){
echo “the first par is $1”
echo “the second par is $2”
echo “the third par is $3”
echo “the scritp name is $0”
echo “the number of par is $#”
}
inp b a 2 3 ab
[root@allen shell]# sh fun.sh
the first par is b
the second par is a
the third par is 2
the scritp name is fun.sh
the number of par is 5
[root@allen shell]# cat fun1.sh
#!/bin/bash
sum() {
s=$[$1+$2] #两个函数求和
echo $s
}
sum 1 10
[root@allen shell]# sh -x fun1.sh
- sum 1 10
- s=11
- echo 11
11
[root@allen shell]#ifconfig |grep -A1 "enp0s3: " |grep ‘inet’ |awk ‘{print $2}’
10.1.1.135
#精准获取IP地址
[root@allen shell]# cat ifconfig.sh
#!bin/bash
ip()
{
ifconfig |grep -A1 "enp0s3: " |grep ‘inet’ |awk ‘{print $2}’
}
read -p "please input the eth name: "
ip $eth
[root@allen shell]# sh ifconfig.sh
please input the eth name: enp0s3
10.1.1.135